Wednesday 26 October 2016

php - Send Email from Localhost XAMPP





May I know how to send an email from localhost to gmail or other email accounts? I already make research regarding this matter and tried to do it but still can not send the email. Below are my sendmail.ini and php.ini files that I edit,



sendmail.ini



smtp_server=smtp.gmail.com
smtp_port=465

smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
auth_username=khairulamran.nazri@gmail.com
auth_password=[email password]
pop3_server=
pop3_username=
pop3_password=
force_sender=khairulamran.nazri@gmail.com
force_recipient=

hostname=smtp.gmail.com


php.ini - mail function



SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off



contact.php - to send the email



if(isset($_POST['submitted'])){
$name=$_POST['name'];
$to=$_POST['email'];
$hp=$_POST['hp'];
$subject="Test";
$msg="Thank you for Register. Your Name is ".$name." and Hp no. is ".$hp;

$header="khairulamran.nazri@gmail.com";
$success=mail($to,$subject,$msg,$header);
if($success==true){
echo "Email send successfully ";
} else{
echo "Error sending email";
}
}
?>


Nama:


Email:


Hp:




If click Submit, it will not send the email that have been submitted.


Answer



Try to use mailer library. I had used and it will work perfectly.

Follow this. https://github.com/PHPMailer/PHPMailer



You would need to only enter your gmail credentials and after that it will work.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...