Saturday, September 3, 2011

How to send email using PHP on WAMP

Hello guys, Today I was trying to fix my friends code problem, He was just trying to send email using php which was running on WAMP Server. Then I recollected this details and shared with him. Here is the step by step guide:

PHP Code for sending an email using mail() function :

 $toAddress = "";
 $emailSubject = "Sample Email";
 $emailBody = "Hello,\n\n\nJust Tesing This Code?";
 if (mail($
, $
, $
)) {
echo("<p>Email successfully sent!</p>"); } else { echo("<p>Error: Email delivery failed...</p>"); } ?>

Configuration in php.ini :
To make the above coe work, you have to set few value in your php.ini of your WAMP installation. Its quit easy to do this, just find your php.ini and replace the default values with the appropriate . 

; For Win32 only.
SMTP = mail.example.come ; for Win32 only
smtp_port = 25
sendmail_from= ; for Win32 only

Now you can use this code for sending emails using your php server which is running either on localhost or on some live domain.

I hope this information is helpful to you. Please share your comments.
Thanks for reading.

No comments:

Post a Comment