简体   繁体   中英

change sender email address in php form to recipient

I'm trying to create a simple php email form that sends the submitted contents to a specified address, but the problem I'm trying to fix is the address the email is being sent from — currently, it sends from myusername@myhostingservice.com, but I want to be able to change that to a simple no-reply@mydomain.com or something else.

<?php 

$message = $_POST['message'];

$formcontent="$message";

$recipient = "reciever@example.com";

$subject = "question";

mail($recipient, $subject, $formcontent, $header, '-fno-reply@mydomain.com') or die("Error!");

header("Location: webpage_user_is_redirected_to.html");

?>

You can use the 5th parameter of the mail function:

mail($recipient, $subject, $formcontent, $header, '-fno-replay@mydomain.com');

From the manual :

The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM