Page 1 of 1
why this code doesn't send mails?
Posted: Sun Jul 31, 2011 12:01 am
by ashiland
Hi I have set up a license selling website, it works with paypal IPN, everything works well except the mail function, where could be the problem please?
here is the code in brief:
Code: Select all
<?php
$payer_email = $_POST['payer_email'];
$mail_To = $payer_email;
$mail_Subject = "Your license";
$mail_Body = $content;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$first_name.' <'.$payer_email.'>' . "\r\n";
$headers .= 'From: mysite <no-reply@mysite.com>' ."\r\n";
mail($mail_To, $mail_Subject, $mail_Body, $headers);
?>
Many thanks in advance.
Re: why this code doesn't send mails?
Posted: Sun Jul 31, 2011 9:26 am
by social_experiment
ashiland wrote:where could be the problem please?
Are you receiving any error messages
Re: why this code doesn't send mails?
Posted: Sun Jul 31, 2011 9:40 am
by ashiland
I don't get any error messages. actually before getting to these lines all the $_post data including $payer_email are stored in the database and everything works well, sending email is the last step.
Re: why this code doesn't send mails?
Posted: Sun Jul 31, 2011 10:30 am
by social_experiment
Code: Select all
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$first_name.' <'.$payer_email.'>' . "\r\n";
$headers .= 'From: noreply@mysite.com' ."\r\n";
?>
It could be a problem with the headers, try the example above and remove the 'To' header aswell. Also, modify the 'To' header to only include the email address.
Re: why this code doesn't send mails?
Posted: Sun Jul 31, 2011 1:30 pm
by phazorRise
Instead of writing a new mail class or function you can use
phpmailer or
swiftmail libraries.
Main issue arises when you send the mail successfully and it gets marked as spam. So these libraries can be helpful for many purposes. You can send attachments, different content types, using external smtp's for sending mails.
But if you want to use your own, it has to be able to tackle the spam filters.
Re: why this code doesn't send mails?
Posted: Sun Jul 31, 2011 1:44 pm
by ashiland
social_experiment is right, the problem is with this line :
Code: Select all
$headers .= 'To: '.$first_name.' <'.$payer_email.'>' . "\r\n";
it works when I change it to :
Code: Select all
$headers .= 'To: Mike <abc@example.com>' . "\r\n";
but this is not what I need, I don't know how I should fix this.