20 May 2009 2 Comments

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();
Tags:

2 Responses to “WAMP SMTP Server – Send outgoing emails”

  1. Tim 20 May 2009 at 10:02 am #

    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. Satyendra Kumar Sharma 30 August 2009 at 8:18 am #

    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