I am trying to send plain/text email to gmail using the following PHP code: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "elearnindia123@gmail.com"; $email_subject = "Sree Vizag Marketing-Tiles Enquiry"; $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $phone = $_POST['phone']; // not required $comments = $_POST['comments']; // required $email_message .= "First Name: ".$first_name."\n\n"; $email_message .= "Email: ".$email_from."\n\n"; $email_message .= "Telephone: ".$phone."\n\n"; $email_message .= "Comments: ".$comments."\n"; //create email headers $headers = "From: $email_from"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $mail_sent = @mail($email_to, $email_subject, $email_message, $headers); echo $mail_sent ? "Mail sent" : "Mail failed"; } ?> PHP: Using this code the email does not show up in the gmail inbox.Any kind of help will be appreciated. srinivas.
Did you check other mail servers or spam folder on gmail? These lines seem strange: //create email headers $headers = "From: $email_from"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); PHP: I think they should be something like this: //create email headers $headers = "From: $email_from\n"; $headers .="Reply-To: .$email_from\n"; $headers .= "X-Mailer: PHP/" . phpversion(); PHP: Also did you get "Mail sent" mesage?
Yes, what AsHinE said, its your lines that construct the header. $headers = "From: $email_from\n"; $headers .="Reply-To: .$email_from\n"; $headers .= "X-Mailer: PHP/" . phpversion(); Code (markup): Try that and echo them out to check them. Its highly likely that this is the problem.
Hello AsHinE , I have added the header as: //create email headers $headers = "From: $email_from\n"; $headers .="Reply-To: .$email_from\n"; $headers .= "X-Mailer: PHP/" . phpversion(); On emailing the message,I am getting "Mailsent" message. Still not getting the mail in theinbox of gmail is there anything more to done in header injection.
Hello getlandersgetpaid, I modified the header with concatination as follows $headers = "From: $email_from\n"; $headers .="Reply-To: .$email_from\n"; $headers .= "X-Mailer: PHP/" . phpversion(); Still not getting the email in the inbox of gmail. Is there anything more to be done in the header injection,mail() function is returning true.
There is nothing wrong in your code. If you receive the "message sent", then your script is definitely shooting the email out. But, due to your IP address reputation or due to the lack of SMTP authentication, gmail may be ignoring your email(considering it as spam.) I would suggest adding the SMTP authentication in the phpmailer script to send out emails. Kindly find the same code below. function send_mail($fromname, $from, $toname, $to, $subject, $body) { require_once('class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = ""; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = ""; // sets the SMTP server $mail->Port = ; // set the SMTP port for the GMAIL server $mail->Username = ""; // SMTP account username $mail->Password = ""; // SMTP account password $mail->SetFrom($from, $fromname); $mail->AddReplyTo($from, $fromname); $mail->Subject = $subject; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress($to, $toname); if(!$mail->Send()) { return 0; } else { return 1; } } PHP:
I am using PHPMailer to send email through gmail account.Thanks langtusitinh225 for your kind advice.
Yes in PHP with mail() function I am getting return "message sent" as return value.Now I am using PHPMailer for sending the email.Thanks,exaspring for your kind advice and code.
maybe your message filtered as spam, because first, like others say that's a header like from and etc then you must fill all body message.
i have a simple question as i am new to php . What is the difference between using phpmailer function and using simply mail() function for sending mail. how phpmailer is efficient that mail() .
phpmailer() is more reliable, and convenient as it supports more options. whereas mail() is unreliable namely on shared hosting, many users of that hosting may use the function, if some of them abuse it and send spam..theirs a chance of your host being blacklist which could lead to the email being sent to the trash/spam folders.
try to use whitelist services, your mail server is the problem i think it was blacklisted by spam filters.
your hosting server dis-abled function mail() so it stopped any outgoing email my hosting was the same till i contact them and told him i'm not using for spam