PHP Mail Don't Show "To" in "To" Header - php

I want to make an email forwarder similar to cPanel's, where I have a database of email addresses, and where they should forward to, and I set a catch-all to pipe to my script.
I have completed this script, however, I would like to make the "To:" field in the header show the address it was sent to, rather than who is was being delivered to. For example, the email was sent to user001#mydomain.com, and the script forwards it to me#gmail.com. How can I make PHP send mail to me#gmail.com, but still show user001#mydomain.com in the headers, like cPanel does?

You can use the headers of the mail function:
$to = 'me#gmail.com';
$subject = 'Testing';
$message = 'This is a test';
$headers .= 'To: User001 <user001#mydomain.com>, User002 <user002#mydomain.com>' . "\r\n";
$headers .= 'From: My Email Script <me#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);

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

Getting mail for a bounced email

I am sending email using mail() The problem is I am not getting an email to a specific email id if the recipient id does not exists, I have tried the following code.
$email="abcdt01est#gmail.com";
$usermsg="some message here";
$subject = 'Your Account Registration Confirmation';
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Our Team <team#test.com>" . "\r\n";
$headers.="Return-Path:<my email id goes here>\r\n";
mail($email, $subject, $usermsg, $headers);
I have also tried with
mail("abcdt01est#gmail.com", "subject", "body of message", "From: team#test.com", "-f<my email id>");
Mail function in PHP mail() only informs about E-Mail has been accepted by the outgoing server, and plays no role in checking E-Mail's actual delivery status.
You can check your mail log /var/log/mail.log if sendmail is configured properly.
Visit this http://www.phpclasses.org/package/9-PHP-PHP-mailer-to-compose-and-send-MIME-messages.html - MIME E-mail message sending: PHP mailer to compose and send MIME messages.

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.

change email address that is being used in server

i'm setting up a system that whenever a user registers on my site it will automatically send a confirmation email.
My problem is that the email that is using ends with info#buick.websitewelcome.com which is weird because my website is not buick.websitewelcome.com.
My expected email should be info#myaddress.info.
How would I do that, i'm using CPanel FYI.
This is also my code when sending the confirmation address
function SendUserEmailVerificationCode( $code,$username,$email_address ) {
// multiple recipients
$to = $email_address;
// subject
$subject = 'Verification Code';
// message
$message = "
Dear ".$username."<br><br>
You received this email because you registered at http://myaddress.info/.<br>
To complete registration please enter this registration code<h1>".$code."</h1></strong> on the link below:<br>
http://myaddress.info/verifyMe.php?username=".$username."
";
$headers = 'From: info#myaddress.info' . "\r\n";
// To send HTML mail, the Content-type header must be set
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
}
Any help would be greatly appreciated and rewarded!
Try the command line paramter -f as shown on http://php.net/manual/en/function.mail.php#example-3048
<?php
mail('nobody#example.com', 'the subject', 'the message', null,
'-fwebmaster#example.com');
?>
The fourth argument in the mail() function is used for headers as you have already noticed. Just add a From header. This will change the from field.
$headers .= 'From: info#mywebaddress.com'."\r\n";
Additionally, if you also want to change the envelope mail from (which you probably want), you can use the fifth argument. This is used for options that should be passed directly to sendmail. Here, you should add -f info#mywebaddress.com. A simple example is shown below.
mail('recipient#domain.com', 'Subject', 'Message',
'From: info#myaddress.info','-f info#myaddress.info');
And also, all of this is mentioned in the official PHP manual on mail().
-f will set the From address, -r will override the default Return-path that sendmail generates (typically the From address gets used).
Ref: PHP Manual: mail

mailed by php how to use it?

How can i use the mail by header in php?
This is what i use now:
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: test#gmail.com\r\nReply-To:test#gmail.com";
//send the email
$to = "test#gmail.com";
$subject = "This is a subject";
$body = "Hi there!";
if (mail($to, $subject, $body,$headers))
{
echo("\nMessages successfully sent!");
} else {
echo("\nMessages delivery failed...");
}
I get this on my gmail when i click on show details:
from test#gmail.com
reply-to testreply#gmail.com
to test#gmail.com
date Sat, May 14, 2011 at 12:06 AM
subject stefanos neofitidis! You commented on your poem:Tree present
mailed-by ip-1-1-1-1.ip.secureserver.net
i do not want to the ip-1-1-1-1.ip.secureserver.net to show up to the users...this is what i am trying to change!
Do you mean the X-Mailer?
$headers = "From: test#gmail.com\r\nReply-To:test#gmail.com\r\nX-Mailer: PHP/" . phpversion();
What you want to do is add a fifth parameter in your mail() function, which needs to use the "-f" sendmail option.
For example:
mail($to, $subject, $body, $headers, "-fsender#domain.com");
Sending a message with that last parameter will change the envelope sender to "sender#domain.com". Most of the time, email providers like gmail won't even show that address if it is set by hand(which is what you want, I'm assuming).
See http://us2.php.net/function.mail for more details.

Categories