php mail() recipient address missing - php

My website runs the following code: (I BCC myself so that I have a copy of all the emails that my website sends out)
//prepare email headers
$headers = "From: " . "info#mysite.com" . "\r\n";
$headers .= "Reply-To: ". "info#mysite.com" . "\r\n";
$headers .= 'Bcc: sent#mysite.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = getMsg( ... );
mail( $buyer_email, 'mysite.com - Verify your information.', $message, $headers );
$message = getMsg( ... );
mail( $seller_email, 'mysite.com - Verify your information.', $message, $headers );
The emails get sent out perfectly fine. The problem is with the second email that gets BCC'ed to me. The recipient's email address is blank so I can't see who the email was sent to. The first email that's BCC'ed to me is fine, all the info shows up. In other words, I can see $buyer_email, but I can't see $seller_email. Any ideas?

You can debug it like this
echo "Seller Email: $seller_email";
mail( $seller_email, 'mysite.com - Verify your information.', $message, $headers )
The page will print the seller email and you can see what it actually is.
Addition
If you can not use the above code because you have to test it a user (which is normal btw), use the following technique.
Since you are getting the first email, send $seller_email as part of test code in that email and see what value it has.
$message = getMsg( ... );
mail( $buyer_email, "mysite.com - Test Seller Email: $seller_email .", $message, $headers );
You will find out the seller email value in the email you get.

Does sending additional headers help? (see mail()) That way you don't have to use 2 mail functions.
Like this:
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";

I'm very sorry, but I made a huge mistake. Long story, but basically I was confusing code on one page with very similar code on a different page. I was testing the validity of $seller_email on the wrong page. On the page in question, it was in fact NOT being set. Once again, sorry. I should have posted the entire code.

Related

email with php BCC and To relations and also spam issue

i am having a issue with sending emails with cronjobs.
actually i need to send email to all the recently joined users
and so the emails are something like $to='acx1#xyz.com,acx2#xyz.com,acx3#xyz.com';
here i need to send the mail to all the receipts but not to let them know that i have sent this mail to all these persons in receipt basically BCC them
but the problem is that if i put the $to into BCC then what should i put in to function of mail
if to is empty then it may be spamed
i want to send this mail to all the receipts but when they check the headers they should see their email only
and one more issue please let me know if i am using correct headers ?
because sometimes my email is spammed by gmail
$from='tests.com';
$to='contact#test.com';
$message="<body> some html data with inline css </body>"
$subject="Hii this is test";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: $from <contact#test.com>" . "\r\n";
$headers .= "Reply-To: contact#test.com" . "\r\n";
$headers .= 'BCC: acx1#xyz.com,acx2#xyz.com,acx3#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);

Wierd characters at the end of any email: PHP MAIL

Well I am using the PHP MAIL function and for some reason every email it sends has a weird;

This is at the end of any email as I said, I am not quite sure why this is happening.
$from = 'From: support#phycraft.co.uk';
$to = $user_email; // Send email to our user
$subject = 'PhyCraft Support Ticket :: Closed :: ' . $t_subject; // Give the email a subject
$message = '
Hello '. $username.'.
Your support ticket '.$t_subject.' has been closed due to being inactive for 48 hours.
If you still need help with the ticket please reopen the ticket by replying to it.
~PhyCraft
';
$headers = 'From:support#phycraft.co.uk' . "\r\n"; // Set from headers
mail($to, $subject, $message, $from); // Send our email
I can't see what in the code woud make that appear to be honest.
Most issues with php's mail() function are problems with the MTA and not with PHP itself. I've never heard of this before making it even more likely it's a MTA issue.
You've not provided any useful information beyond the PHP code. What OS is this on (mail() on MSWindows is very different from everyhere else). Do you control the server? What MTA is configured? Have you tried sending an email from the command line?
The extra stuff at the end looks like HTML - is this byte for byte what's in the email or what you see in your mail client?
BTW it's not a good idea to explicitly put "\r\n" at the end of your headers - but you seem to have forgotten to add them as a parameter. Also, your missing a space between "From:" and the email address.
Can you try it with following $headers ( only \n ).
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset = \"ISO-8859-1\";\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: support#phycraft.co.uk\n";
$headers .= "\n";
mail($to, $subject, $message, $headers);
and 2. try it without
$headers .= "Content-Transfer-Encoding: 8bit\n";

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;

How to add custom header to PHP mail?

I have a mail function with the standard parameters:
mail($to, $subject, $message, $headers);
Where:
$headers = "From: admin#mysite.org";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
Now, I'm trying to get the sent e-mails to show 'My Site' as the sender instead of 'admin#mysite.org' but if someone responds to the mail it still needs to go to admin#mysite.org.
I've tried putting "My Site" in the "From" field before and after the e-mail address but it just appends to the address. I've tried appending it to the $headers variable but that messes the whole e-mail up. I've also tried adding it this way:
$headers .= "\r\nMy Site";
but that doesn't seem to do anything.
I know this can't be complicated as I've seen it done a hundred times, but I can't seem to find a straight-forward answer for this - how do I 'mask' the admin e-mail with the site name but still keep it as the address any response goes to?
Change your From: header to "From: My Site <admin#mysite.org>"
$headers = "From: My Site <admin#mysite.org>";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
From the PHP Docs.
There is the "From: something <something#something.com>"; header, and then there is also the optional fifth parameter of mail() which allows you to override the from setting that may or may not be set in php.ini.
<?php
$to = 'name#domain.com.au';
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: Name <noreply#domain.info>" . "\r\n";
$fifthp = '-f noreply#domain.info';
mail($to, $subject, $message, $header,$fifthp);
?>

Can't post to facebook page by email from php

you can send a status update to a facebook page you own by sending it to a cretin (secret) email address. this is described here:
http://www.facebook.com/help/pages/mobile
the problem is I cant make it work from php
function page_publish_by_mail($page_mail, $status){
$to = $page_mail;
$subject = $status;
$message = "";
$headers = "From: my#mail.address";
return mail($to, $subject, $message, $headers);
}
I can send mail to my email address and I can post by mail from my email address but I can't seem to post by mail from PHP.
I haven't tried to send to facebook mail before, however I feel like it is being filtered out due to lack of header information. Try adding some more header details.
I always send headers like this:
$headers = 'From: Your Name <youremail#domain.com>' . "\r\n";
$headers .= 'Content-type: text/html' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
This is set up to send an html email, but you might try other content-types if that doesn't work.
It may be a good idea to look in the documentation and see if there are other headers that are required as well.

Categories