How to Send Email from a PHP Script Using SMTP Authenticatio
Posted: Sat Mar 06, 2010 11:47 pm
Hello All!
I am not a professional php coder and even don't have great experience in php. I was coding a feedback form on my site using php and its working on one of my server but not working on another server. When I asked about it to the hosting company they told me to use SMTP authentication it. I don't know how to use SMTP authentication in my coding. So please can anybody help me in this... You can check my code here :
<?php
/* This form is designed and developed by Deziners Studio*/
$c_name = $_POST['c_name'];
$c_designation = $_POST['c_designation'];
$c_address = $_POST['c_address'];
$c_phone = $_POST['c_phone'];
$c_email = $_POST['c_email'];
$c_requirement = $_POST['c_requirement'];
$todayis = date("l, F j, Y, g:i a") ;
// Creating header for sending email to Site Administrator
$header = 'From:' . $c_email . "\r\n";
// Creating subject for sending email to Site Administrator
$subject = "$c_email has submitted contact request form on your site...";
// Putting Site Administrator's email id for sending email
$send_to = "kp@dezinersstudio.com";
$message = "Dear Administrator,\n\n
You received career request through contact request form on $todayis [EST] from $c_email ...\n
The Details are as below:\n\n
<strong>$todayis [EST]</strong> \n
<strong>Name :</strong> $c_name \n
<strong>Designation :</strong> $c_designation \n
<strong>Address :</strong> $c_address \n
<strong>Phone No. :</strong> $c_phone \n
<strong>Email :</strong> $c_email \n
<strong>Requirement :</strong> $c_Requirement \n
";
// Send message to Site Administrator
$success = mail ($send_to, $subject, $message, $header);
if ($success)
{
//Creating confirmation message to send to the user
$user_email = $c_email;
$from_email = "no-reply@dezinersstudio.com";
$receipt_subject = "Confirmation of your career request...";
$receipt_header = 'From: ' . $from_email . "\r\n";
$receipt_message = "Dear $c_name, \n\n
Your request for contact on $todayis [EST] has been received and forwarded to our
concerned department. We will get back to you within 24 hours. \n
Thanking you. \n\n
Best Regards, \n
Deziners Studio \n
http://www.dezinersstudio.com";
// Send the confirmation mail to the user
mail ($user_email, $receipt_subject, $receipt_message, $receipt_header);
header('Location: success_contact.html');
}
else
{
header('Location: contact.html');
}
?>
I am not a professional php coder and even don't have great experience in php. I was coding a feedback form on my site using php and its working on one of my server but not working on another server. When I asked about it to the hosting company they told me to use SMTP authentication it. I don't know how to use SMTP authentication in my coding. So please can anybody help me in this... You can check my code here :
<?php
/* This form is designed and developed by Deziners Studio*/
$c_name = $_POST['c_name'];
$c_designation = $_POST['c_designation'];
$c_address = $_POST['c_address'];
$c_phone = $_POST['c_phone'];
$c_email = $_POST['c_email'];
$c_requirement = $_POST['c_requirement'];
$todayis = date("l, F j, Y, g:i a") ;
// Creating header for sending email to Site Administrator
$header = 'From:' . $c_email . "\r\n";
// Creating subject for sending email to Site Administrator
$subject = "$c_email has submitted contact request form on your site...";
// Putting Site Administrator's email id for sending email
$send_to = "kp@dezinersstudio.com";
$message = "Dear Administrator,\n\n
You received career request through contact request form on $todayis [EST] from $c_email ...\n
The Details are as below:\n\n
<strong>$todayis [EST]</strong> \n
<strong>Name :</strong> $c_name \n
<strong>Designation :</strong> $c_designation \n
<strong>Address :</strong> $c_address \n
<strong>Phone No. :</strong> $c_phone \n
<strong>Email :</strong> $c_email \n
<strong>Requirement :</strong> $c_Requirement \n
";
// Send message to Site Administrator
$success = mail ($send_to, $subject, $message, $header);
if ($success)
{
//Creating confirmation message to send to the user
$user_email = $c_email;
$from_email = "no-reply@dezinersstudio.com";
$receipt_subject = "Confirmation of your career request...";
$receipt_header = 'From: ' . $from_email . "\r\n";
$receipt_message = "Dear $c_name, \n\n
Your request for contact on $todayis [EST] has been received and forwarded to our
concerned department. We will get back to you within 24 hours. \n
Thanking you. \n\n
Best Regards, \n
Deziners Studio \n
http://www.dezinersstudio.com";
// Send the confirmation mail to the user
mail ($user_email, $receipt_subject, $receipt_message, $receipt_header);
header('Location: success_contact.html');
}
else
{
header('Location: contact.html');
}
?>