This question already has an answer here:
My web developer made this script to send notifications to people subscribing to my mailing list and the people who contact me, through the form on my website The problem is, the recipients are not able to receive the emails, and I am not able to receive the notification on my mail id about a new subscriber or a contact
Sender id - notifications@llaveshagarwal.com
Moreover, the same script works on his server (which we used for testing) but doesn't work on my server
Is there a problem with my SMTP server settings ? Also, I am using Google Apps for Gmail Here is his script
What should I do ?
<?php
if($_POST['type'] == "subscribe") {
/*$to = "notifications@llaveshagarwal.com";
$subject = "New Email Subscriber";
$txt = "Name: ".$_POST['name']."
From: ".$_POST['from'];
$headers = "From: ".$_POST['from'];
mail($to,$subject,$txt,$headers);
$to = $_POST['from'];
$subject = "Thank you for subscribing with us.";
$txt = "Hey ".$_POST['name']." ,
Greetings from LLavesh Agarwal Textile Agency
Thank you for subscribing with us for Exclusive and Latest Catalogs and product launches.
We will update you soon.
Regards,
Team LLavesh Agarwal
*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello@llaveshagarwal.com";
$headers = "From: notifications@llaveshagarwal.com";
mail($to,$subject,$txt,$headers);*/
$link = mysql_connect('localhost', 'llavesha_admin', 'Admin@1234');
$db= mysql_select_db('llavesha_contact_system', $link);
$insert='insert into subscribe (name,email) values ("'.$_POST["name"].'","'.$_POST["from"].'")';
if(mysql_query($insert)) {
echo "success";
} else {
echo "fail";
}
}
elseif($_POST['type'] == "contact") {
$to = "notifications@llaveshagarwal.com";
$subject = "New Contact";
$txt = "Name: ".$_POST['name']."
Contact: ".$_POST['mobile']."
Category: ".$_POST['bussiness_type']."
Description: ".$_POST['project_detail'];
$headers = "From: ".$_POST['from'];
mail($to,$subject,$txt,$headers);
$to = $_POST['from'];
$subject = "Thank you for contacting us.";
$txt = "Hey ".$_POST['name']." ,
Greetings from LLavesh Agarwal Textile Agency
Thank you for contacting us.
We will update you soon !
Regards,
Team LLavesh Agarwal
*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello@llaveshagarwal.com";
$headers = "From: notifications@llaveshagarwal.com";
mail($to,$subject,$txt,$headers);
echo "success";
}
?>
</div>
Are you working on windows (wamp)? Have you enabling php sendmail on php.ini? read: http://us3.php.net/manual/en/function.mail.php
or you can read: php mail() function on localhost
If you want to make it simpler, use phpmailer instead: https://github.com/PHPMailer/PHPMailer
How to use it by @pooria: How to configure PHP to send e-mail?
require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = 'This is the message';
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Username = 'me.sender@gmail.com';
$mail->Password = '123!@#';
$mail->SetFrom('me.sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycomp.com','no-reply');
$mail->Subject = 'subject';
$mail->MsgHTML($body);
$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */
$mail->AddAttachment($fileName);
$mail->send();