Php mail function issue - php

I'm trying to send a email to user after successfully register. So that following is my .php code.
$to = $email;
$subject = "Signup | Verification";
$message = "Congratulation $f_name $l_name you have been successfully registered. Please
click the link to active your account.\r\n";
$message .= "http://www.maaks.fr/hotel/verify.php?email=$email&hash=$hash\r\n";
$from = "noreply#yoursite.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-rype: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding; 7bit\r\n";
$headers = "From:" . $from . "\r\n";
$sentmail = mail($to,$subject,$message,$headers);
if($sentmail)
{
header("Location: thankyou.php?member=successfully");
exit();
}
It doesn't sent a email to the user. I checked it that if $sentmail is ok then It's go thankyou page. But interesting matter is that it's go to thankyou page without sent a email.
Is there anything i forgot?

The mail() function returns true if the message was accepted for delivery, it doesn't mean the message will be delivered.
From the Manual:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
Your message is probably being blocked by the recipients spam filter or going straight to the junk folder.

There is one minor typo in your email message but I don't think it will solve your problem.
You have a Content-rype specified, you should change that to Content-type...
But again I don't think that will solve your problem.

Related

PHP Web Form Not Sending To Gmail Email

I have a php form that I made and when someone fills out the form it works fine with all other email accounts (yahoo, hotmail, #mydomain.com, etc) but when it comes to sending the email to a gmail user, the email never comes through, not even in the spam box.
$from = $email;
//Testing Below
//$headers = 'From:noreply#mydomainname.com' . "\r\n";
$headers .= "From: $from \n";
$headers .= " MIME-Version: 1.0\r\n ";
$headers .= " Content-Type: text/html; charset=ISO-8859-1\r\n ";
//Mail The Message
mail($to, $subject, $message, $headers);
The code above will not send to gmail but will work for all other email accounts. This one (below) will work for gmail but of course then I don't have the option of html in the email.
$headers = 'From:noreply#mydomainname.com' . "\r\n";
//$headers .= "From: $from \n";
//$headers .= " MIME-Version: 1.0\r\n ";
//$headers .= " Content-Type: text/html; charset=ISO-8859-1\r\n ";
//Mail The Message
mail($to, $subject, $message, $headers);
So basically when I add the MIME and Content type to the headers variable it wont send to a gmail account.
Thanks in advance!
I have replied a question not too long ago related to this. It might have to do with the gmail's email filtering, maybe you are getting too high spam score so it's not even getting into the spam folder, this could be caused by not having correct dns configuration / keys and trying to use html at the same time.
I leave a link to the other answer (It's quite long, and not as easy as you would imagine xD):
PHP and Gmail spam filter
Hope it helps you.
You are not using a proper concatenation operator:
Change your From line to:
$headers .= "From: ".$from;

Why is this PHP script failing to send HTML mail?

I have this piece of test code to send an HTML email. For the longest time, it was sending, but not sending in HTML format. And now, it's not sending at all.
I've been comparing with code on the PHP manual, and with similar questions on this site, and I can't see anywhere that the code could be wrong. It's driving me crazy.
Why is this code not sending, and why is it not sending in HTML?
$to = "myemail#mysite.com";
$subject = "Confirmation code for registration";
$message = "<html>
<head>";
$message .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
$message .= "<title>TITLE</title>
</head>
<body>";
$message .= "Thank you for registering! \r\n";
$message .= "
</body>
</html>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf-8\r\n";
$headers .= "From: My Site <registration#mysite.com>r\n";
$mailresult = mail($to, $subject, $message, $headers);
echo "mail sent! ";
echo $mailresult;
$mailresult comes back as 1, which I assume means success, but no mail is being recieved at the mail account specified.
According to php.net:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
Have you configured a mail server to send the mail?
Your code worked on my server perfectly but I received the email as Spam - so check your spam. And do your research to check if your server is configured properly.
Try doing
mail($to, $subject, $message, $headers);
without $mailresult

Mail sent with mail() function does not get sent [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php mail function
I am doing this website where I send emails to users when they for example forget their password or similar, but for some reason I can not send emails with the following function:
$email = 'somemail#mail.com';
$subject = 'subject';
$message = 'message blablablablabla';
mail($email, $subject, $message);
Am I doing something wrong or missing something in the code, or is it the hosting company's fault? (I make my website on x10hosting.com). I checked in the manual about mail() but it didn't help me.
Thanks in advance.
Update
Thanks for the help guys, but it turned out to be a problem on the web hosting company I'm on. Everything's working fine now.
try to use with headersenter code here
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: <".$frommail.">\r\n";
$headers .= "Reply-To: ".$frommail."\r\n";
$mail_sent=mail($tomail, $msg, $headers);`enter code here`
I would guess either there is no sendmail_from value set in php.ini or your host does not support email or has not set it up correctly.
Try setting a from header, and if that doesn't work, contact your host:
mail($email, $subject, $message,'From: you#example.com');
is this on local host? or is it on a webserver
Also remember that mail($to, $subject, $contents) returns a boolean,
if(mail($to, $subject, $body){
echo "Message has been sent";
}
else{
echo "Error has occurred"
}

sending mail with link and parameter in PHP

I have a strange issue with sending a mail with php, here is my code:
$link = "http://www.somelink/verify.php?id=".$uniqID;
$message ="<html><head></head><body><p>Full Name:".$data[0]." ".$data[1]."</p>";
$message .="<p>Flight Number: ".$data[4]."</p>";
$message .="<p>The Ride: ".$curPlace." to ".$data[5]."</p>";
$message .="<p>Number of Passengers: ".$data[3]."</p>";
$message .="<p>Date:".$data[6]." time:".$data[7]."</p>";
$message .="<p>The price: ".$data[8]."</p>";
$message .="<p>To verify the reservation press this link</p></body></html>";
$headers = 'From: my#email.com' . "\r\n" .'Reply-To: some#email.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Sensitivity: Personal"."\r\n";
$sent=mail($data[2],"Taxi Reservation",$message, $headers);
if($sent){
echo "Message was sent to ".$data[2];
}
else{
echo "Message was not sent";
}
The problem is with Gmail.If I send it as is, I get the success message, but get nothing in my gmail, but do get in another not gmail account.
BUT!
If I delete a tag from this line:
$message .="<p>To verify the reservation press this link</p></body></html>";
I do get the message in Gmail.So I can't understand what's the problem.
What can couse this problem?
Thank you for your help.
If your email is not arriving at Gmail, but the same code sending the same email is arriving at a different account, I suspect that the problem is that Gmail are seeing your email and classifying it as spam - have you checked to see if it's gone into your spam folder instead of your inbox?
Gmail has a set of rules to identify what they think is spam - presumably, including the link is enough to push your email into the spam category.

PHP mail isn't sending - headers set incorrectly?

I have successfully sent mail using PHP's mail() function before, and for my password reset notification e-mail, I copied the syntax I was using elsewhere, but I guess I messed it up, as it's not arriving at its destination. Here is the code I'm using:
$headers = 'To:'.$email."\r\n";
$headers .= 'From: webmaster#aromaclear.co.uk'."\r\n";
$to = $email."\r\n";
$subject = 'AromaClear Password Reset Notification'. "\r\n";
$msg = 'From: AromaClear'."\r\n";
$msg .='Subject: Your New Password'. "\r\n";
$msg .= 'Message: Your new password is '.$newpass."\r\n";
$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";
mail($to, $subject, $msg, $headers);
Any thoughts?
Try looking at your server's mail logs to see why it isn't getting forwarded. Ex., it may be that this server's sendmail wants the -f flag for the From header instead of specifying it in the header text.
mail($to, $subject, $msg, $headers, "-f $from");
Also, you seem to be doing a lot of extra/weird work. This is a lot easier:
$subject = "AromaClear Password Reset Notification";
$headers = "From: webmaster#aromaclear.co.uk";
$msg = "Your new password is $newpass\r\nIf you have received this e-mail in error, please ignore it.\r\n.";
if(mail($email, $subject, $msg, $headers))
{
//handle success
}
else
{
//handle failure
}
Change style to your preference.
have you checked the return value of mail(). If it's not FALSE then it's accepted for delivery and the code is fine, but something is messed up somewhere else.
That looks fine to me, perhaps do
if (mail($to_email,$subject,$message, $headers))
echo 'Success';
else
echo 'Error';
}
That might let you know if it's trying to send at all.
Just don't add "\r\n" everywhere, use it only to separate headers.
In the message you can use only \n, it will work.
And at the end of the subject and receiver there's no need for "\r\n".

Categories