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 :
<?php
$toAddress = "user@sampleexamples.com";
$emailSubject = "Sample Email";
$emailBody = "Hello,\n\n\nJust Tesing This Code?";
if (mail($toAddress
, $emailSubject
, $emailBody
)) {
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= admin@example.com ; 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.