Send PHP Mail via SMTP



When you send email using PHP mail() function then the email is sent from web server. This can cause issues, if the FROM address is not correct.

The best solution is to send email via SMTP because email is sent from the mail server than web server and email is instantly delivered.

In the below example, I have explained how to send email using SMTP PHPMailer.

Name :

Email :

Mobile No. :

Message :

	
IsSMTP();
	$msg ="
		Name : $n1
		Email : $e1
		Mobile : $m1
		Message : $m2
	";

	$mail->SMTPAuth = true;
	$mail->SMTPSecure = "ssl";
	$mail->Host = "yourdomainname";
	$mail->Port = 465;
	$mail->Username = "username";
	$mail->Password = "password"
	$mail->AddAddress("Receiver Email Address");
	$mail->SetFrom("Sender Email Address");
	$mail->Subject = "Subject";
	$mail->MsgHTML($msg);
	if($mail->Send())
	{
		echo "Thanks! We will contact you soon.";
	}
}
?>

Comments