WAMP SMTP Server – Send outgoing emails

If you are running WAMP and you want to be able to send outgoing e-mails via PHP’s mail function, then you will need to edit the php.ini file and change

SMTP = localhost

to

SMTP = smtp.yourisp.com

Replacing smtp.yourisp.com with the address of your ISP’s SMTP server, e.g. smtp.ntlworld.com. The php.ini is in the bin directory of the active Apache, which will be something like:

c:\wamp\bin\apache\apache2.2.8\bin

However, if you are using Zend Mail and you get an error along the lines of

Warning: mail() [function.mail]: SMTP server response: 501 <"Bill Gates" <[email protected]>>: "@" or "." expected after """"

Then you should probably bypass PHP’s mail functions altogether, and connect directly to the SMTP server from Zend Mail:

require_once 'Zend/Mail/Transport/Smtp.php';
$tr = new Zend_Mail_Transport_Smtp('mail.example.com');
Zend_Mail::setDefaultTransport($tr);

So to send a mail from WAMP using Zend Framework’s Mail functions, you would use the following:

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';

$tr = new Zend_Mail_Transport_Smtp('mail.example.com');
Zend_Mail::setDefaultTransport($tr);

$mail = new Zend_Mail();
$mail->setBodyText($setBodyHtml);
$mail->setFrom('[email protected]', 'Bill Gates');
$mail->addTo($email, $name);
$mail->setSubject($subject);
$mail->send();