php mailer is not working hotmail - php

<?php
$to = 'xyz#hotmail.com';
$subject = 'the subject';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: acb#gmail.com' . "\r\n" .
'Reply-To: acb#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 'hi hello';
mail($to, $subject, $message, $headers);
echo 'mail sent';
?>
As I am sending mail using above code .. it is working fine ..
but mails are not going to hot mail...
can anyone help me in this please

This can be a plethora of things. One of the more common ones is that you are telling them you are sending mail from a gmail account but are not actually connecting to them from a gmail server.
If you could provide us with more information (specifically, lines concerning delivery from your mail.log) we could help better but most likely it is either that you aren't allowed to send mail for gmail and/or that your server is marked as "bad" by hotmail.

The hotmail spam filter stopped it, and with good reason. Advise i can give you:
Send it to yourself, and see the raw message. You may find that the From: address has changed and differs form the Reply-To:. To avoid that, send the email via SMTP instead.
If the domain you send from has a SPF DNS record, that may help. Spam filters use this to look up the authenticity of emails that claim to come from a certain domain.
This is why the #gmail.com address you used is certainly not going to pass through..

Related

Why don't I see any mails in sent mail or the recipient doesn't receive any mail that is sent using sendmail in php? [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
php code:
<?php
$to = 'vickee#hotmail.com';
$subject = 'Testing sendmail.exe';
$message = 'Hi, you just received an email using sendmail!';
$headers = 'From: vignesh#gmail.com' . "\r\n" .
'Reply-To: vignesh#gmail.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>
I have enabled second step verification in gmail. Is the prob due to that and I get "Email sent" when I run the php code. But there are no mails in the sent or recipient's inbox or junk folder. Are there any alternative methods? If so, please comment link for step by step procedure to send emails using the service.
EDIT:
I've setup the mailing part as instructed in http://arpanthakrar.blogspot.in/2013/06/send-email-from-localhostwamp-server.html
Please do let me know if there are anyother methods or changes to be made in this method.
Let me clearify a bit the "sending" of E-Mail:
$to = 'vickee#hotmail.com';
...
$headers = 'From: vignesh#gmail.com' . "\r\n" .
that means: send an email to "vickee, coming from vignesh"
That does not mean: "Use gmail to send an email to vickee"
Instead, PHP is using the local mailer to transport the mail. The mail is passed by your box, your providers MTA etc. to vickee's inbox at hotmail.
Your gmail account is not involved in to this. So looking in to the "sent" folder of your gmail account doesn't make sense, instead look in to vickees inbox.
Edit:
The "real" sending of the mail is done by the local MTA (Mail Transfer Agent). This is either sendmail, postfix or any other local service.
It's not part of or task of PHP.
PHP is only passing the mail to the configured MTA (usually locally).
Thus: you need to check your e-mail setup first!

How to format an email that Hotmail / Outlook is happy with?

$body = 'This is a test';
$subject = 'Confirmation';
$headers = 'From: Testing Site' . "\r\n";
$headers .= 'Reply-To: admin#myserver.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion(). "\r\n";
$headers .= 'Delivery-Date: ' . date("r") . "\r\n";
//$headers .= 'Message-Id: <20140316055950.DA8ED58A13CE#myserver.com>' . "\r\n";
mail("example#hotmail.com", $subject, $body, $headers, "-f admin#myserver.com");
mail("example#gmail.com", $subject, $body, $headers, "-f admin#myserver.com");
Emails send fine to Gmail but are always rejected by Hotmail with this error:
host mx1.hotmail.com[65.55.33.119] said: 550 5.7.0 (COL0-MC5-F28)
Message could not be delivered. Please ensure the message is RFC 5322
compliant. (in reply to end of DATA command).
Message ID header is generated automatically by the server but it doesn't help to supply one manually either.
Why isn't Hotmail happy?
Mail server has SPF record, reverse DNS, is not blacklisted and passes all checks at mxtoolbox.com.
The From header is invalid. It must have the following syntax:
From: "name" <email-address>
In your case:
From: "Testing Site" <admin#myserver.com>
The same goes for your Reply-To header:
Reply-To: "Testing Site" <admin#myserver.com>
Which you can omit if it's the same as the From header (like in your case).
PS: RFC 2822 doesn't state that the display-name in an address should be quoted. In other words: the following 3 headers should all work:
From: "Testing Site" <admin#myserver.com>
From: 'Testing Site' <admin#myserver.com>
From: Testing Site <admin#myserver.com>
If you're using WordPress, you can look up plugin for Hotmail/Outlook friendly emailing capability.
However if it is a standalone script you might wanna look into Microsoft's official answer to this query on the URL : http://answers.microsoft.com/en-us/outlook_com/forum/oemail-osend/why-are-the-emails-sent-to-microsoft-account/b64e3e4a-0d93-40c8-8e28-4be849012f9c
In-short Email-Server provider has to fill this form (once) : https://support.live.com/eform.aspx?productKey=edfsmsbl3&ct=eformts&wa=wsignin1.0&scrx=1
In order to get their emails accepted by Hotmail/Outlook.
Using the PHPMailer library to send mail instead of the mail() function has finally sorted this problem and is the working solution for me. Answer by Jasper N. Brouwer probably more correctly answers the question though I've not had a chance to try it.
1 ) Go to SPF record wizard
2) create a new SPF record for your DNS domain
3) Add that DNS record to your domain's DNS
4) if you fail somewhere in the process, read the detailed SPF record specification
After you complete this process HOTMAIL will be happy with your email.

Send multiple emails using PHP

I working on a project in which i need to develop a functionality to send multiple emails to client with one click and i am adding customer id in one text box separating them with comma.
Please tell me how to do this problematically. Your advice
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
if you want to send the user as in db jus replace the $to address from db and place these code in loop.
php.net's mail function page explains this well
to be fair we all had to start somewhere. The problem with using "vanilla PHP mail" is that it is almost always used when people send mail as spam. So for 10 years mail servers haven't liked it. There are ways round it but to be brief:
To send Email via a webpage you "should"
have your mail server resolve RDNS
try to avoid cheap/free web hotels as mailserver hosts
use PHP PEAR MAIL (this is tricky/odd to install)
properly apply the correct headers for the mail in PEAR
Check below link may be help you.
http://www.quackit.com/php/tutorial/php_mail.cfm

Sending email from domain different than primary? Possible?

this may be a noobish question. I'd like to know if I can send emails from the server that say, domain1.com is associated with, as coming from domain2.com and also having the origin show as coming from domain2.com?
The reason I'd like to do this, is because I have an application I'm developing and would like to send emails from the domain, for example - maildomain.com instead of coming from domain.com
Emails are being sent with php's mail function.
Yes, you can:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example-two.com' . "\r\n" .
'Reply-To: webmaster#example-two.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
You should set up some things, so the receiver doesn't mark it as spam though:
Set up DNS MX records with low priority for the receiving domain, pointing to sending server
Setup correct reverse DNS entries for sending server
..
The "From" address in an email is entirely arbitrary. As long as you have permission to submit mail to a server's queue, you can put any From address in it that you want. president#whitehouse.gov, julian#wikileaks.org, etc.
To do this with PHP's mail() function, use *$additional_headers*. For example:
$to = "whoever#example.com";
$subject = "This is an example!";
$message = "Hello,\n\nThis is message body.\n\nIsn't that nice?\n\n";
$headers = "From: El Presidente <president#whitehouse.gov>\r\n"
. "X-foo: bar\r\n";
$result = mail($to, $subject, $message, $headers);
Possible? Yes is sure is. See the below example from PHP.net. However, I'm going to put a little piece of fine print here, as I think you might run into some trouble, and I want to make it easier for you in the future. ;) Your current webhost may block this, I've never seen it, but I've heard it can happen. Also, there is a thing called SPF, or Sender Policy Framework, that is a DNS record that you can set to determine what servers can send on your behalf. Many servers that could receive your mail, and especially GMail check for valid SPF. All you have to do is add a TXT record on your name server for domain.com. It should look something like this: v=spf1 mx a:maildomain.com -all. This says any records that have an MX record set up, and the IPs that are resolved from maildomain.com are valid 'non-spam'. Also, you will to fail any other mail origin.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
If the mail server is an open mail relay then yes, you can send from a different domain. It is of course seen as a vulnerability as spammers can use it to send out junk mail. The configuration of the mail server to get this functionality depends on its platform but you can usually test a server's ability to freely relay messages by telneting to the server on port 25 and doing an ehlo test.

how to know if php mail failed

I am sending mails from php mail() : and I want to receive a failed message if sending is failed to the destinatio .
$to = 'itsdfdsf#7sisters.in';
$email_from = "info#7sisters.in";
$full_name = 'XXXX';
$from_mail = $full_name.'<'.$email_from.'>';
$subject = "testing sender name";
$message = "";
$message .= '
<p><strong>This is only a test mail. Please do not reply.</strong><br />
';
$from = $from_mail;
//$headers = "" .
// "Reply-To:" . $from . "\r\n" .
// "X-Mailer: PHP/" . phpversion();
$headers = "From:" . $from_mail . "\r\n" .
"Reply-To:" . $from_mail . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if(!mail($to,$subject,$message,$headers))
{
echo 'failed !!';
}
But although $to mail does no exist,it is not showing failed !!
The mail method is just sending the mail out. If it does not receive any errors (e.g. by not finding the server etc), it will return succesfull. You will not be able to know if the mail actually landed in the inbox of the recipient unless you create some code around bounced emails etc.
I think what you want is to check for a real email not only a valid formatted email. So I would suggest you to have a look at this blog
check the return from of mail
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.
Although the fact it is returning true probably means that your mail program is accepting the message but then failing when it tries to send to no one...
You should run the $to through a validator to check its a valid address and then throw an error if its not, don't rely on mail() to filter out things which you already know are wrong, or can check against easily.
--UPDATE
Then check out #SeRPRo , but what your trying to do is hard work to test programatically - its far easier and more reliable to send an e-mail which requires the user to click a link to verify that it's real than try querying SMTP servers which all have different behaviour (read: are broken to different degrees). Also note that your intended behaviour (code wise) is hard to differentiate from a spammers so don't be surprised to find it difficult going if you avoid the verification e-mail route.
But although $to mail does no exist,it is not showing failed !!
actually the fact that mail is being delivered to SMTP server, doesn't mean it will be delivered to the end user. There's no easy way in PHP to check whether it's delivered.
You could CC yourself as a way of testing that it is leaving the outbox.
In my case it helped to set the return-path via the commandline parameter "-f", which can be passed in the $additional_parameters parameter of mail(). so i call
mail($to, $subject, $message, $headers, "-f address.where.i.want.the.bounces#xy.com");
... according to some comments on http://www.php.net/manual/en/function.mail.php hosting-inviroments react different and have different restrictions (address might need to be registered in the same hosting-account, or be on the same domain, the same as the "From:" in the heade ... and so on)
The page where I got the bounces to be received (with non of the mentioned restrictions, as it seems) is hosted at Domainfactory http://www.df.eu
Use phpmailer to send email and set $mail->AddCustomHeader('Return-path:bounce#mail.com');
This will send bounce email at bounce#mail.com if recipient mail id does not exist or recipient does not receive email by any other case.

Categories