PHP and the mail() function - php

I am using a PHP script to send e-mails to a list of friends. This used to work successfully but now the only e-mails that are sent successfully are those inside my domain ("mycompany.com"). Any e-mails outside my domain fail to be sent. Is this a problem with permissions? Could I fix it by changing the headers I use when I call the mail() function? Here is the PHP script:
$name = "Joe Smith";
$email = "jsmith#mycompany.com";
$to = "ajones#mycompany.com, tom#abc.com, ted#def.com, mary#ghi.com";
$subject = "Dinner Invitations";
$message = "Invitation to Dinner";
$headers = "From: ".$name."<".$email.">\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Return-Path: ".$email."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
mail($to, $subject, $message, $headers);
Only ajones#mycompany.com was sent out by the server. tom#abc.com, ted#def.com, and mary#ghi.com did not get sent.
Any suggestions would be deeply appreciated!

Related

Why is my PHP script not sending emails when set from header

I have a php script that is only sending mail when the user registration.
I put in something along the lines of:
$to ='testmail#gmail.com';
$message = 'Hello';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Website <admin#example.com>\r\n";
if($results= mail($to, 'User Registration', 'Test', $headers)) {
echo 'success';
} else {
echo 'fail';
}
But the email doesn't send on server. When i put the following line :
$headers .= "From: Website <admin#example.com>\r\n";
Why is this happening?
Have you looked at the answer to smtp configuration for php mail it's very similar a question to yours?

php mail function is not working on online server [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
i want to send a mail the code is given below. i cant understand waht is happening . It works on localhost but not on live server.
if (isset($_POST['test_mail'])){
$to = '2606ankit#gmail.com'; //put email address on which mail send
$subject = "Newsletter"; //Put subject of mail here
$from = 'ankit#studiokrew.com'; //put email address from
//email body start
// $body .= file_get_contents('file/'.$filename.'');
$body .= 'anio';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: '.$from. "\r\n";
//if you need to send cc mail then uncomment below line and change email address
//$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$body,$headers);
}
try this..
<?php if (isset($_POST['test_mail'])){
$host=$_SERVER['HTTP_HOST'];
$replyto="<no-reply >";
$to ='2606ankit#gmail.com';
$subject = "Newsletter";
$from = 'ankit#studiokrew.com';
$headers = "From: \"Invoice\"<noreply#$host>\n";
$headers .= "Reply-To: ".$replyto."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"abc"\"\r\n\r\n";
$headers .= 'From: '.$from. "\r\n";
$header .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$body = "This is a multi-part message in MIME format.\r\n";
$body .= "Content-type:text/html; charset=iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= 'anio';
mail($to,$subject,$body,$headers);
}
?>
check the MTA logs on your server.also web server logs the answer will be there somewhere.
Test with a simple mail() script that does not require any external data, just to make sure that your server indeed can send mail. If that fails, you'd have to contact the server admins for help.

Personalised 'To' field when sending large email list using PHP mail and multiple addresses in the Bcc

Im trying to remember a trick i was taught a while back but can not.
Basically, im using PHP mail() in this fashion:
$to = "emailAddress1#domain.com";
$subject = "Welcome to BuildSanctuary";
$messageContent = "Thankyou for registering Bla bla bla";
$message = 'SOME HTML EMAIL STUFF including the $messageContent var';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Accounts<accounts#domain.com>' . "\r\n";
$headers .= 'Bcc: emailAddress1#domain.com,emailAddress2#domain.com,emailAddress3#domain.com,emailAddress4#domain.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
I got told a while back that there was a way that you could put your own email in the to field, but when the users receive the emails it looks like they were personally sent the email and the to field shows just their email.
Is this possible? Cant think how.
Thanks.

php mail function - how can changing From: in header cause email not to be sent?

The one email From:support#lead.com works fine. But when changed to john.doe#lead.com it doesn't work? See below.
Both are valid email addresses (fictitious for this example) in the domain from which they are sent.
I have the question into Netfirms support too. I expect to move to phpmailer or API to a ESP (e.g., mailchimp) account soon, but this is just bugging me that the little change breaks the email function.
Code:
Works:
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: support#lead.com' . "\r\n";
$headers .= 'Bcc: bcc#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#mylead.com")) echo ("Message delivery failed");
Doesn't Work: (only changed support to john.doe):
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: john.doe#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#lead.com")) echo ("Message delivery failed");
Don't know how this really should matter, but you're mixing \n and \r\n in the headers, which may confuse your mail server... Would you mind to try this out?

custom php email settings?

I have this logic
$subject = "something.com Signup -
Please do not reply to this email. It was automatically generated.";
$body = "A new person has signed up to receive something updates:";
$headers = "From: webinquiries#something.com\n";
$headers .= "Reply-To: something#gmail.com\n";
// $headers .= 'Bcc: something#something.com' . "\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\n";
mail($email, $subject, $body, $headers);
which seems ok but one thing.... can i set the smtp info like this
server="smtp.something.net",
username="webinquiries#somthing.com",
password="asda.1sda",
port="587"
you can set the server in php.ini, but user\password as php's build in mail does not support authentication. you should look at a third party library (phpmailer) as the php mail() function's very under powered.

Categories