I have Plesk with a Network Solutions virtual server. When my site sends out emails using PHP, the email header indicates that the message is coming from an address like this one:
anonymous#002a1c9.netsolvps.com
How do I change this address?
Using the PHP mail() command, you can set the envelope from address using the -f command, and you can include the from address in the message headers as well, like so:
$to = "to#to.com";
$from = "from#from.com";
$subject = "subject";
$message = "this is the message body";
$headers = "From: $from";
$ok = #mail($to, $subject, $message, $headers, "-f " . $from);
Related
I am trying to send an email to user once he signs up on my localhost project, I am working on Xampp and my OS is Mac, I know this function is correct:
$to_email = "receipient#gmail.com";
$subject = "Simple Email Test via PHP";
$body = "Hi,nn This is test email send by PHP Script";
$headers = "From: sender\'s email";
if (mail($to_email, $subject, $body, $headers)) {
echo "Email successfully sent to $to_email...";
} else {
echo "Email sending failed...";
}
But there is something to configure in SMTP i guess? however I can't find what and where to edit on MAC, thank you in advance.
If you want to send a mail from a local server using for example XAMPP, you will need to use the mail server in order to do it.
Do something like this:
<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL#gmail.com");
$message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail#address.com";
$headers = "From: YOURMAIL#gmail.com";
mail("Sending#provider.com", "Testing", $message, $headers);
You will most likely need the mail account's credentials in order to send a mail.
Also, check out Sending email with PHP from an SMTP server.
I have static ip on my home computer.
I am using windows-7 with xampp .
I creat the code for sending mail
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail( $to, $subject, $message, $headers );
echo "Mail Sent.";
?>
but sir mail is not received at destination.
I thinks is it possible to send mail from my home computer using windows7 xampp??
plz answer
See your answer here http://www.c-sharpcorner.com/UploadFile/c8aa13/send-mail-on-local-host-via-mercury-with-xampp/
Or here https://www.google.ru/search?q=use+mercury+to+send+email
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.
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);
This question already has answers here:
How to change envelope from address using PHP mail?
(6 answers)
Closed 8 years ago.
$to = "me#mydomain.com";
$subject = "Auction Registration Confirmation";
$from = "From: donot-reply#mydomain.com";
$body = "Test Message";
if (mail($to, $subject, $body, $from)) {
echo("<b>Message sent</b>");
header( "Location: http://www.mydomain.com/thankyou.html" );
} else {
echo("<b>Message failed</b>");
}
Now the problem is that when an email is sent, the from address is not what I require, but the server login name.
Any ideas as to replace the server login name with the from email id.
YOu could try
mail($to, $subject, $body, $from, "-f $from");
this works in some configurations, really depending on the server setup.
Otherwise, edit your MTA settings as recommended above, or skip mail() altogether and use a class like PHPmailer that connects directly to the SMTP server.
There doesn't look to be anything wrong with your PHP code - I have very similar code doing the same job and it works fine.
Possibly there's something misconfigured with your email setup?
The PHP mail function relies on the MTA running on your server. I would bet that your MTA is setup to force the $from variable to your login name.
did you try this? it works for me fine
<?php
$to = "email#to.com";
$subject = "subject";
$message = "message";
$from = "email#from.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>