Php mail out to mobile / sms / text; missing from, via headers - php

For some reason, when php mail() is sent to a text number (via email) i.e. 123456789#vtext.com; the from shows up as the centos apache server output email (apache#host-name.com). However, I've included the correct headers; so when the same mail() is pushed to (for example) gmail it comes and shows normal with all the correct headers / mime type / from.
Any idea?
Here's the code for the normal mail
$headers = "From: Alert#thedomain.com \r\n";
$headers .= "Date: ". date('r') . "\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";
$headers .= "MIME-Version: 1.0 ";
$body = "body message";
mail($userinfo->username,"thedomain",$body,$headers);
And the code for the mobile: (We don't use date/content type/ mime for text msgs, or else the headers shows up in the txt msg)
$headers = "From: Alert#thedomain.com \r\n";
$body = "body message";
mail($userinfo->mobile,"thedomain",$body,$headers);

Try sending with the additional -f flag to the mail function:
mail($userinfo->username,"thedomain",$body,$headers, "-ffromaddress#example.com");
See the manual for more information on additional parameters

Related

PHP Disposition-Notification-To

I'm trying to get a read receipt from my PHP emails, here's my code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "From: ABC <do-not-reply#abc.com> \n";
$headers .= "Disposition-Notification-To: abc#hotmail.com \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
I tried opening the email on my phone and outlook. In both cases, received no email to confirm that the email was open.
I also tried
$headers .= "Read-Receipt-To: abc#hotmail.com \n";
And
$headers .= "X-Confirm-Reading-To: abc#hotmail.com \n";
Read receipts are entirely up to the receiver, there is no way to guarantee one, and many webmail clients will explicitly ignore this for privacy reasons.
Try using Outlook (the office suite application, not the webmail/hotmail clone, not sure which you used) and seeing if you get a popup that says "do you want to send a read receipt? yes / no"

How to send email to yahoo via PHP

I am attempting to send a confirmation email from a PHP script. I tested on gmail and it worked fine (the email was sent with appropriate subject and contents), however when I tried sending an email to a yahoo account, the subject field was correct but the contents were sent as an attachment as opposed to text inside the actual email. Here is the mailing code.
$headers = 'From: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= 'Reply-To: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= "BCC: orders#COMPANY_NAME.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text; charset=ISO-8859-1\r\n"
mail($email, "COMPANY_NAME Order Confirmation $confirmation_number", $text, $headers);
How can I send an email to yahoo that will include $text inside the email as opposed to an attachment?
It may be because of a wrong "Content-Type" header: I do not think "text" is a valid content type.You should try, instead, with "text/plain".
Content-Type: text/plain; charset=ISO-8859-1
PS: you may also want to consider using UTF-8 instead of ISO-8859-1.

Getting empty mails from website

I have php 4.x installed in server, I have a script to send mails, generally 1 Out of 10 mails i receive will have no body but the subject will be there. The mail sending code is below.
$headers = "MIME-Version: 1.0 \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$headers .= "From: Contact Form <contact_form#mycompany.com> \r\n";
$headers .= "Request Form: $name ($contactid)";
$subject = "Request: $name";
$body = "Name: $name<br />Email: $email<br />Phone: $phone<br/>";
mail("myname#gmail.com",$subject,$body,$headers);
What is the reason behind it. Is this the problem with the script i have written or the SMTP server.
According to RFC 2822:
Header fields are lines composed of a field name, followed by a colon (":"), followed by a field body, and terminated by CRLF.
A field name MUST be composed of printable US-ASCII characters (i.e., characters that have values between 33 and 126, inclusive), except colon.
Your header does not follow this format. Some receiving mail servers may be more strict and may refuse your mails because of that. Change it to:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Contact Form <contact_form#mycompany.com>\r\n";
$headers .= "Request-Form: $name ($contactid)\r\n";
\r : Carriage Return
\n : Line Feed
Does it fix your problem?

Form doesn't send info to email address (works on others though)

My client has a Wordpress content management system to which I added a simple contact form with a php form handler. The contact form sends the information by email correctly to all three of my email addressses, but when I change to my client's email address the email never arrives. I have run out of ideas where I could look for the problem. No it does not go to his junk mail folder. :)
Sounds like the email is being routed "internally" through your clients network and not out onto the internet. The chances are they have some restrictions on what machines can be used to send emails internally, or the mail routing system sees the internal email as being "different" and does something odd with it.
Try using (from a cli) :
echo "Testing " | mailx -"Test Subject Line" user#company.co.uk
What is the mail function that you are using? Do you attach a header to it? It sounds like it is being marked as spam from the exchange server. What I use (and have always worked for me) is something like this:
`
function mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc="")
{
$subject = nl2br($subject);
$sendmailbody = nl2br($sendmailbody);
if($bcc!="")
{
$headers = "Bcc: ".$bcc."\n";
}
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8 \nContent-Transfer-Encoding: 8bit\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: PHP/"."MIME-Version: 1.0\n";
$headers .= "From: " . $from . "\n";
$headers .= "Content-Type: text/html\n";
mail("$sendto","$subject","$sendmailbody","$headers");
}
`

html email issue for a tag value

I am sending html email to the client via php mail function. while & sign shown in bold creating problems in email replacing ! %20 something like characters within my ids such as below(in bold).
http://test.com/test-page.php?id=abcd**!**1234&cat_id=23
Below is my code.
$to = 'test#abc.com';
// subject
$subject = 'test';
//message
$message.='<html><head><meta charset="UTF-8" /></head><body><p>Wine **&** Dine Offers</p></body></html>';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: test <test#abc.com>' . "\r\n";
$headers .= 'From: test user <no-reply#test.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
After sending mail i am getting ! and %20 like characters in email.
I also tried & except & in email but no use still ! adding within my email html.
Try running urldecode() on the incoming parameters. Example:
$id = urldecode( $_GET['id'] );
I think you should encode the URL on the email. Plus, you probable have magic_quotes_gpc "on" that is not recommended.
I always use PHPMailer, it saves a lot of work and helps on these problems
try this:
$toName = 'test';
$toAddress = 'test#abc.com';
$fromName = 'test user';
$fromAddress = 'no-reply#test.com';
// subject
$subject = 'test';
// URL for link
// this should have any URL encoded characters literally in the string
$url = 'http://test.com/test-page.php?id=abcd1234&cat_id=23&msg=URL%20encode%20this%20string';
// HTML for message
// Call htmlspecialchars() on anything that may need it (like the URL)
$messageHTML = '<html><head><meta charset="UTF-8" /></head><body><p>Wine & Dine Offers</p></body></html>';
// Text version of message
// Remember, not everyone has an HTML email client!
$messageText = "Wine & Dine Offers: $url";
// Build a multipart MIME message
$boundary = '------'.md5(microtime()).'------';
$body =
"This is a multipart message in MIME format.\r\n"
."$boundary\r\n"
."Content-Type: text/plain\r\n"
."\r\n"
."$messageText\r\n"
."$boundary\r\n"
."Content-Type: text/html; charset=UTF-8\r\n"
."\r\n"
."$messageHTML\r\n"
."--$boundary";
// To send HTML mail, the Content-type header must be set correctly
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n";
// Additional headers
// the To: header will be set by mail() and is not required here
$headers .= "From: $fromName <$fromAddress>\r\n";
// Mail it
mail("$toName <$toAddress>", $subject, $body, $headers);
I changed the encoding settings on phpmailer to use base64 encoding using
$mail->Encoding=”base64"
This solved my problem.
As there is issue for HTML mail meassage exceeds length 998 or something i got the above solution to it. :)
http://www.jeremytunnell.com/posts/really-hairy-problem-with-seemingly-random-crlf-and-spaces-inserted-in-emails

Categories