This article applies to:
[ Zend Core V2.x ]
[ IBM System i ]
Preface
The PHP mail() function is used to send emails from inside a script.
The following mail extension is provided with the zend core for i5/OS products and should already be loaded with the core installation. zmail - Zend SMTP module
Details
The PHP mail() Function
The PHP mail() function is used to send emails from inside a script, PHP Simple E-Mail Syntax:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
|
Parameter
|
Description |
Required |
| $to |
Specifies the receiver / receivers of the email |
X
|
| $subject |
Specifies the subject of the email. Note: This parameter cannot contain any newline characters |
X |
| $message |
Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters |
X |
| $headers |
Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n) |
|
| $parameters |
Specifies an additional parameter to the sendmail program |
|
PHP Simple E-Mail
- Altering the mail() options Dynamically with ini_set():
- PHP's ini_set() function temporarily sets a given configuration option for the duration of the program that invoked it.
- ini_set() takes two parameters
- Varname—Variable/option to change
- Newvalue—Value to change to
- The following lines of code show how to set the SMTP server and "from" address within a PHP function.
Example:
<HTML>
<body>
MAIL SETTING for Iseries<br>
Define a real name of your mail Server<br>
<center>
SMTP = mail.zend.com </center>
<br>
Define a real name of your mail Server<br>
<center>
smtp_port = 25</center>
<br>
Define an any address you want<br>
<center>
sendmail_from = shlomo@zend.com</center><br>
</body>
<?php
// Using the ini_set()
ini_set("SMTP", "mail.zend.com");
ini_set("sendmail_from", "shlomo@zend.com");
//ini_set("smtp_port", "25");
// The message
$message = "The mail message was sent with the following mail setting:\r\nSMTP = mail.zend.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";
// Send
$headers = "From: shlomo@zend.com";
mail('shlomo@zend.com', 'My Subject', $message, $headers);
echo "Check your email now....<BR>";
?>
</HTML>
- Setting the mail() options Static php.ini parameters:
[mail function]
SMTP = mail.zend.com
smtp_port = 25
sendmail_from = shlomo@zend.com
Example:
<HTML>
<body>
MAIL SETTING for Iseries<br>
Define a real name of your mail Server<br>
<center>
SMTP = mail.zend.com </center>
<br>
Define a real name of your mail Server<br>
<center>
smtp_port = 25</center>
<br>
Define an any address you want<br>
<center>
sendmail_from = shlomo@zend.com</center><br>
</body>
<?php
// Using the php.ini static entries
// The message
$message = "The mail message was sent with the following mail setting:\r\nSMTP = mail.zend.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";
// Send
$headers = "From: shlomo@zend.com";
mail('shlomo@zend.com', 'My Subject', $message, $headers);
echo "Check your email now....<BR>";
?>
</HTML>
Troubleshooting
- Changes to PHP.INI will take effect after the Apache server is restarted
- To view mail() unexpected behaviour, see PHP's error log: /usr/local/zend/Core/logs/php_error_log
- The error log may be viewed with a text editor or this command: EDTF '/usr/local/zend/Core/logs/php_error_log'
Note:
Make sure the mail() extension is loaded use the GUI to load and enable the extension, than restart the apache from the i5 use the green screen menu: GO ZENDCORE/ZCMENU