Preface
The PHP mail() function is used to send emails from inside a script.
The following mail extension is provided with the Zend Server for IBMi OS products and should already be loaded with the product 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 IBMi<br>
Define the name of your mail Server<br>
SMTP = mail.company.com<br>
Define your mail Server port<br>
smtp_port = 25<br>
Define a sender email address<br>
sendmail_from = SenderMail@company.com<br>
</body>
<?php
// Using the ini_set()
ini_set("SMTP", "mail.company.com");
ini_set("sendmail_from", "SenderMail@company.com");
//ini_set("smtp_port", "25");
// The message
$message = "The mail message was sent with the following mail setting:\r\nSMTP = mail.company.com\r\nsmtp_port = 25\r\nsendmail_from = SenderMail@company.com";
// Send
$headers = "From: SenderMail@company.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.company.com
smtp_port = 25
sendmail_from = SenderMail@company.com
Example:
<HTML>
<body>
MAIL SETTING for IBMi<br>
Define the name of your mail Server<br>
SMTP = mail.company.com<br>
Define your mail Server port<br>
smtp_port = 25<br>
Define a sender email address<br>
sendmail_from = SenderMail@company.com<br>
</body>
<?php
// 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 = SenderMail@company.com";
// Send
$headers = "From: SenderMail@company.com";
mail('shlomo@zend.com', 'My Subject', $message, $headers);br /> 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 behavior, see PHP error log:
/usr/local/zendsvr6/var/logs/php_error_log - The error log may be viewed with a text editor or this command:
EDTF '/usr/local/zendsvr6/var/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 IBMi use the Green Screen Menu: GO ZENDSVR6/ZSMENU
Comments