This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
So I have a normal but long HTML form on this page
The PHP mail script for the form is:-
$to = "something#gmail.com";
$from = $_POST['contact_email'];
$subject = "Application form submission";
$message = "<h2>Tell us what you need?</h2>";
$message .= "Loan Amount Required ?";
$message .= "<br>";
$message .= $_POST['tell_loan_amount'];
$message .= "<br>";
$message .= "<br>";
$message .= "What For?";
$message .= "<br>";
$message .= $_POST['tell_what_for'];
/* and so on */
$headers = "From: $from" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if( mail($to,$subject,$message,$headers)) {
echo "<h1>Thank you for the Application</h1>";
echo "<p>We will now review the application. This process normally takes 2-3 Business Hours. If we need to discuss any aspect of the application we will contact you. If you have any questions at all please do not hesitate to contact us on <strong>1300 815 462</strong></p>";
}
else {
echo "failed";
}
Now the problem is that mail only gets sent sometimes. I have had several clients contact and said that they successfully reached the thank you page and received the success message but we never received the mail. And yes, not in Spam either.
Is it happening because it is set to gmail?
Or is it happening because of incorrect encoding? (Our clients are filling form in English.)
Or do I need to use mb_send_mail() instead of mail() and remove the encoding code altogether?
use this command on you server it will output what happen to your sent mail :
tail -f /var/log/maillog
sometimes the provider block port 25
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I am using PHP mail function to send a mail with shared hosting of GoDaddy, previously email is getting in the inbox but now I am getting email in the spam box instead of inbox.
Below is my code:
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$to = $email;
$from = $email;
$CC = 'myname#gmail.com';
$subject ="Testing";
$htmlContent = '
Dear '.$name.' from '.$company.',
\nThank you for your interest in our impact initiatives.
\nPlease reach out to us, we are happy to learn more from you!
\nAll the best,
Dev Team.
';
$headers = "From: ".$name." <".$from.">\r\n";
$headers .= "Cc: $CC";
// if($extension ==""){
$headers .= "\nMIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// }
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// if(!$extension ==""){
// $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
//
// $htmlContent = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//
// $htmlContent .= "--{$mime_boundary}\n";
// }
if(mail($to, $subject, $htmlContent, $headers)) {
header("Location:index.php");
// echo "<p>mail sent to $to and $headers!</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
}
?>
I have used all headers but still I am facing same issue. Kindly let me know if anything needs to change and please give me some suggestions to resolve this issue.
Thank you in advance.
Its is very likely that phpmail function does not fit the anti-spam methords most providers use as the server the mail is being sent from is not recognised as allowed. DKIM, SPF, RIP need to be matched. To find out what gmail does not like about your email would be best to review the headers of the sent message to make sure it fits your domains sending criteria. However if you want to get this resolved quickly using an existing email account or creating a new one for your domain such as website# and using STMP auth should prevent your emails getting flagged as the sending server should already match the needed criteria. Here is a link to a thread that should help: Sending email with PHP from an SMTP server
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I am trying to send emails using a php script whose code is below. What is the error in the code? Parsing error is:
PHP Parse error: syntax error, unexpected 'https' (T_STRING) in /workspace/Main.php on line 9
"""
<?php
$our_email = "agrawal.shivam#godonphone.website";
$to = "agrawal.shivam2602#gmail.com";
$from = $our_email;
$subject = "God Apps on Mobile Phone";
$message = "
God on Mobile! Please go through these contents for your personal growth & distribute to others as well:
echo 'krishna.science.blog';
Share the Love & Knowledge in your physical proximity also.
Physical address: Krishna, Vrindavan, Uttar Pradesh, India (IN), Pin Code:- 281121
echo 'Unsubscribe ";
$mail = mail($to, $subject, $message, "From: $our_email");
if ($mail) {
echo "Mail Sent";
}
else {
echo "Error - Mail Not Sent";
}
?>
Your message is not your website PHP file. You just need to show that the message you are sending is HTML, and write pure HTML instead of using echo PHP statements.
To send HTML use
<?php
$to = 'maryjane#email.com';
$subject = 'Marriage Proposal';
$from = 'peterparker#email.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
As per https://www.tutorialrepublic.com/php-tutorial/php-send-email.php
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
This is my code. I spent hours debugging it. I can't see the error. Why didn't I didn't receive the email?
if(isset($_POST['submit'])){
$to = "admin#example.com";
$subject = "Mesej Website";
$from = $_POST['email'];
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h3>Mesej Daripada '.$_POST['name'].'</h3>';
$message .= '<div style="margin-top:20px;">'.$_POST['message'].'</div>';
$message = '</body></html>';
mail($to,$subject,$message,$headers) or die('mail sending error');
The in built mail function of PHP needs configuration for sending the email.However, if you are using the third party hosting provider this should be already configured or else you need to configure it in php.ini file.
To avoid these configuration issues you can use the phpmailer library where you can all the parameters easily and in a more efficient way.
This question already has answers here:
How do I prevent mails sent through PHP mail() from going to spam? [duplicate]
(6 answers)
Closed 5 years ago.
I have done everything possible but after registration my email goes to spam and i want it to go into inbox
$subject = 'Confirm your email';
$to = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: CGOTY <info#cgoty.com>' . "\r\n";
$body='Hi, Click here to confirm your email https://cgoty.com/activate.php?encrypt='.$encrypt.'&action=activate ';
mail($to,$subject,$message,$headers);
You made a mistake in your script within you mail contructor of function you said message instead of body message instead of body.
So it should look like this
$body='Hi, Click here to confirm your email https://cgoty.com/activate.php?encrypt='.$encrypt.'&action=activate ';
mail($to,$subject,$body,$headers);
It will work for you
Add this to your header:
$headers .= "Reply-To: $email" . "\r\n";
(replace $email with the mail you want)
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My mails using php mail() are going to the junk mail folder - why?
<?php
ob_start();
session_start();
//define the receiver of the email
$from='mrashidap#gmail.com';
$to = 'mrashidap#gmail.com';
//define the subject of the email
$subject = 'inform me please, when u receive this mail';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
#Now We Can Use HTML Tags
$headers = "From: " . strip_tags($from). "\r\n";
$headers .= "Organization: appstribes\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";
$headers .= "X-Priority:3 \r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$headers .= "X-MSMail-Priority: high\r\n";
$msg = '<html><body>';
$msg .= '<p>Dear Sir/Madam</p><br/>';
$msg .= '<p><strong>GOOD DAY..!!!</strong></p>';
$msg .= '<p>Thank you for contacting Keita Customer Service. We regret any inconvenience you have experienced. Your request has been received, and a ticket has been created for you with,</p>';
$msg .= '<p><strong>Reference ID : khd004</strong></p>';
$msg .= '<p>Our team is looking into your request and you can expect next to be contacted with either an answer to your question(s) or a solution to the issue(s) raised. Our expected time-frames to respond will vary according to the severity or complexity of the matter being addressed and volume of contacts reaching us. However we assure you that we are working to get back to you as fast as possible and to properly address your questions and concern.</p>';
$msg .= '<p>Regards,</p>';
$msg .= '<p>Keita IT Team</p><br/>';
$msg .= '</body></html>';
$message=$msg;
//send the email
$mail_sent = #mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
Most of the mails are going to junk. However mail sending to gmail are getting in inbox itself.
Your script claims this email is sent from gmail, which is not true
Not clear whether your server signs emails with DKIM or not, does it have SPF or not
Server may be graylisted
Google may not designate your domain as a permitted sender
Any of these reasons may lead to considering your emails as spam.