Reputation: 19
My code is as given below. I would like to know how to use smtp function in php with authentication in contact form. If I use hotmail id I am not able to recive the inquiry but it works fine for gmail id. It would be great if someone help in me editing my code noted below
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" Name: $name \n Email: $email \n Phone: $phone \n Message: $message";
$to = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $name \r\n";
mail($to, $subject, $formcontent, $mailheader) or die("Error!");
echo "<br><br><p style='color:#000'><b>Thank You $name</b></p><p style='color:#000'>We will be in touch as soon as possible.</p>";
echo "<p style='color:#000'>Go to <a href='index.html'><b>Home Page</b></a></p>";
?>
Upvotes: 1
Views: 65
Reputation: 81
You can use PHPMailer Library to do this.
Example:
$mail = new PHPMailer();
$mail->SMTPSecure = 'tls';
$mail->Username = "[email protected]";
$mail->Password = "Your password";
$mail->AddAddress("[email protected]");
$mail->FromName = "Your Name";
$mail->Subject = "Contact Form";
$mail->Body = "The Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
$mail->Send();
Upvotes: 2