Wierd characters at the end of any email: PHP MAIL - php

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";

Related

How can use BCC in sending multiple mail in PHP mail function

I am trying to send mail to multiple recipient without them seeing each others email address
this is what I have done so far
//my variable $mailto got all the emails from the database
$mailto = preg_replace('#\s+#',',',trim($mailto));
$headers = 'FROM: COMPANY INC <support#admin.com>\r\n';
$headers .= 'BBC'.$mailto."\r\n";
$headers .= 'Content-Type:text/html; charset=ISO- 8859-1\r\n';
mail($mailto, "MY TITle", $mailbody, $headers);
You are setting the wrong header. There is no BBC, and you're missing a colon.
try
$headers .= 'BCC: '.$ml."\r\n";

When i send the email using php in gmail it went to the Spam folder in gmail? How can i prevent that? [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 6 years ago.
please refer the following code.in there am sending username and password.email has sent to the gmail.but it is in spam folder.it happens only in gmail.
Here is my code
$to = $email;
$subject = ' Web Site| login Details'; // Give the email a subject
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$uname.'
Password: '.$upass.'
Web Builder login: '.$ulink.'
------------------------ ';
$headers .= 'From:noreply#ggg.eee.net' . "\r\n";
$headers .= 'Bcc: kae#ggg.eee.net' ."\r\n";
$headers .= 'Bcc: thi#ggg.eee.net' ."\r\n";
mail($to, $subject, $message, $headers);
There are many reasons why email providers mark your messages as spam. Sometimes it has to do with the way your server and DNS are configured or other times it may be the content of your message. I would recommend using this tool to help pinpoint the weak spots of your email messages to help you get through most spam filters
Mail-Tester.com
Use this code may be it work properly
$to = Email;
$subject = ' Web Site| login Details'; // Give the email a subject
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$uname.'
Password: '.$upass.'
Web Builder login: '.$ulink.'
------------------------ ';
$headers = 'From: noreply#ggg.eee.net' . "\r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .= 'Bcc: kae#ggg.eee.net' ."\r\n";
$headers .= 'Bcc: thi#ggg.eee.net' ."\r\n";
$headers .='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('<br>'."Email Sent ;D ".'</br>');
}
else
{
echo("<p>Email Message delivery failed...</p>");
}
I have found the soution of this problem:
Solution-1:
Use double quotes to headers.
Solution-2:
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
https://github.com/PHPMailer/PHPMailer
Source of solution

Outlook receives PHP HTML e-mail as code?

I made an HTML e-mail send with PHP, but my client receives this as pure code. Here is the PHP code to send the mail:
$subject = 'HTML e-mail test';
$message = '<html>
<body>
<h1>TEST</h1>
</body>
</html>';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: <".$to.">\r\n";
$headers .= "From: <".$email.">\r\n";
$mailb = mail($to, $subject, $message, $headers);
It works fine for me, but they receive it as:
Content-type: text/html; charset=iso-8859-1
To: <email#email.com>
From: <email#email.com>
<html>
<body>
<h1>TEST</h1>
</body>
</html>
Is there something wrong with my headers? Or is it their Outlook?
How can I fix this problem?
Thanks in advance!
I see:
Content-typetext/html; charset=iso-8859-1
where I should see:
Content-type: text/html; charset=iso-8859-1
Is that a cut/paste error? In your code, or in your result?
Note that you probably want to include both text/plain and text/html types in a multipart message, since HTML-only mail often gets high spam scores (using SpamAssassin, SpamBouncer, etc).
UPDATE #1:
It appears that the \r\n is being interpreted as two newlines instead of one. Different platforms may have different bugs in their implementation of SMTP. It's possible that you can get away with changing your line endings to just \n. If that works with your system, don't rely on it, as it may not work on a different system.
Also, consider switching to a different method for sending mail. phpMailer and SwiftMailer are both recommended over PHP's internal mail() function.
UPDATE #2:
Building on Incognito's suggestion, here's code you might use to organize your headers better, as well as create a plaintext part:
filter_var($to, FILTER_VALIDATE_EMAIL) or die("Invalid To address");
filter_var($email, FILTER_VALIDATE_EMAIL) or die("Invalid From address");
$subject = 'HTML e-mail test';
$messagetext = 'TEST in TEXT';
$messagehtml = '<html>
<body>
<h1>TEST</h1>
<p>in HTML</p>
</body>
</html>';
// We don't need real randomness here, it's just a MIME boundary.
$boundary="_boundary_" . str_shuffle(md5(time()));
// An array of headers. Note that it's up to YOU to insure they are correct.
// Personally, I don't care whether they're a string or an imploded array,
// as long as you do input validation.
$headers=array(
'From: <' . $email . '>',
'MIME-Version: 1.0',
'Content-type: multipart/alternative; boundary="' . $boundary . '"',
);
// Each MIME section fits in $sectionfmt.
$sectionfmt = "--" . $boundary . "\r\n"
. "Content-type: text/%s; charset=iso-8859-1\r\n"
. "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
. "%s\n";
$body = "This is a multipart message.\r\n\r\n"
. sprintf($sectionfmt, "html", $messagehtml)
. sprintf($sectionfmt, "plain", $messagetext)
. "--" . $boundary . "--\r\n";
$mailb = mail($to, $subject, $body, implode("\r\n", $headers));
I'm not saying this is The Right Way to do this by any means, but if the strategy appeals to you, and you think you can maintain code like this after not having looked at it for 6 or 12 months (i.e. it makes sense at first glance), then feel free to use or adapt it.
Disclaimer: this is untested, and sometimes I make typos ... just to keep people on their toes. :)
One good way to be sure is to change your headers to that of this:
$to = 'bob#example.com';
$subject = 'Website Change Reqest';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Also, double check the rest of your code by comparing to this:
http://css-tricks.com/sending-nice-html-email-with-php/
I would recommend not using PHP's mail() function. Yes, it can send an email, but for anything with any kind of complexity, it just makes things difficult.
I'd suggest using a class such as phpMailer, which will give you a lot more flexibility. It makes it much easier to do things like sending HTML emails, adding attachments, and using alternative MTAs.
I've had this issue myself, it was fixed by using \n instead of \r\n.
I only use \r\n for the last line in the header.
The problem is that some antivirus email scanners treat anything following the mime header as body text.
The fix is to make you mime header the last one.
I just had the same problem with one of my clients and it had me whacked for a while.
This is a problem with Microsoft Outlook (Windows).
The solution is to remove the "\r" at the end of the headers and just use "\n".

php mail() recipient address missing

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.

Mail generated in PHP going to spam [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: How to avoid a system generated e-mail going into spam?
How to send 100.000 emails weekly?
I am using the following script to send mail
$to = 'name#test.com' . ', ';
$to .= 'name2#test.com';
$subject = 'Green apple';
$message = 'Enquiry posted by test ';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Green Apple <info#greenappleme.com>' . "\r\n";
if (mail($to, $subject, $message, $headers))
{
echo "mail send successfully";
}
else
echo "mail can't send";
When I use this script to some servers, the mail is going to spam. But in some servers, it is going to the Inbox as desired.
How can I prevent email going to spam?
To prevent an email going into spam, don't send with mail from PHP. Send it with SMTP from your server, you can use PHP to connect to SMTP and submit the message. You will then need to set the SPF records on your server, and reverse DNS records with whoever your IP address comes from. If you do these three things then you'll be on the whitelist and all your emails will go into the inbox everywhere, assuming you don't abuse the privilege and get put on a blacklist.
So: send using SMTP, research SPF records and reverse DNS.
You won't be able to do this unless you have a dedicated server with dedicated IP for the domain from which you are sending the email from.
Be sure to set the RETURN PATH as the optional 5th parameter to the mail() function.
if (mail($to, $subject, $message, $headers, '-finfo#greenappleme.com'))
TO send ur majority mail in inbox set below headers and dont use test like keywords in your subject line
$headers = "From: My site<noreply#example.com>\r\n";
$headers .= "Reply-To: info#example.com\r\n";
$headers .= "Return-Path: info#example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Categories