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" <bill@microsoft.com>>: "@" 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('bill@microsoft.com', 'Bill Gates');
$mail->addTo($email, $name);
$mail->setSubject($subject);
$mail->send();

3 thoughts on “WAMP SMTP Server – Send outgoing emails”

  1. Wow! This solves the very same problem I was having on the very same day I had it. Coincidence? 😉

    There was a further stumbling block for me in that the setFrom email address (I was using my personal email address) could not be used to send email as it had an SPF record.

    I used test@[myisp.com] instead which did the trick.

  2. Thanks a lot
    You have made my concepts clear related to the PHP and the smtp server.
    Now I’ll be able to use it in my college project !
    I’ll be back to u if I find any such problem……..

Leave a Reply

Your email address will not be published. Required fields are marked *