This is my code:
$to = '[email protected]';
$subject = 'test';
$body = 'test';
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "To: <$to>" . "\r\n";
$header .= 'From: [email protected] \r\n';
mail($to, $subject, $body, $header);
The code works, it sends the email. But the sender is not the one that I defined. The sender seems to be the webmail host. What am I doing wrong?
Just add the -f parameter to provide the sender's email and -F parameter to provide the sender's name to the mail(), all as a string. Assuming that you are using sendmail on a Linux machine: You can find more detailed information by typing "man sendmail" in your shell.
PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );
The php. ini file is where you configure your PHP installation. This is the file you need to edit in order to configure PHP to send mail. You need to ensure that the php. ini file contains details of the mail server that should be used whenever your application sends mail.
Try setting the envelope sender, as well setting the sender in the headers of the message, like so:
$to = "[email protected]";
$from = "[email protected]";
$subject = "subject";
$message = "this is the message body";
$headers = "From: $from";
$ok = @mail($to, $subject, $message, $headers, "-f " . $from);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With