Pages

23 Aug 2013

Contact Form For Mail Code in PHP through using MSN SMTP

Contact Form For Mail Code in PHP through using MSN SMTP

<?php
require_once('mail/class.phpmailer.php'); // download php mailer class

$fname = $_POST['fname']; // required
$lname = $_POST['lname']; // required
$contact = $_POST['contact']; // not required
$email = $_POST['email']; // not required
$address = $_POST['address']; // not required
$pcode = $_POST['code']; // not required
$price = $_POST['price']; // required
$qty = $_POST['qty']; // required
$comments = $_POST['comments']; // required



$strmsg=("<p>Hi, </p><p>Name: $fname $lname </p><p>Contact: $contact </p><p>Email -Id: $email </p><p>Address: $address </p><p>Product Code No.: $pcode </p><p>Price: $price </p><p>Quantity: $qty </p></br>Comments : $comments");

//echo($strmsg);

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.live.com';
$mail->Port = 587;
$mail->Username = 'frommailid';
$mail->Password = 'password';
$mail->SMTPAuth = true;

$mail->From = 'frommailid';
$mail->FromName = 'name';
$mail->AddAddress('emailid');
$mail->AddReplyTo('fromemilid', 'Information');

$mail->IsHTML(true);
$mail->Subject    = "subject";
//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
$mail->Body    = $strmsg;

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Your message was successfully sent! Thank you for contacting us, we will reply to your inquiry as soon as possible!";
}
?>

No comments:

Post a Comment