When we receive messages through our site, the 'sender' of the email is listed as "newwavea@host424.hostmonster.com", rather than the address of the person who submitted a message. Could you check my PHP and see where I've gone wrong? Thanks. Here's the WEBPAGE LINK
<?php
if(!empty($_POST['full-name1']) or !empty($_POST['email1']) ) {
header('Location: success.html');
}
$name = $_POST['full-name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: SSR';
$to = 'info@new-wave-academy.com'; // send to this address
$subject = $_POST['subject'];
$body = "From: $name\n
Email: $email\n
Message:\n $message";
mail($to, $subject, $body);
header("Location: http://new-wave-academy.com/Contact/success.html"); /* Redirect browser */
exit();
?>
From
and Return-path
addresses must be set explicitly. PHP will not parse the message body looking for them (why should it?). Since you aren't setting any, the system will simply use default value set in server config.
You can use the $additional_headers
parameter for sender and, in many numbers, you can use $additional_parameters
for the return address:
bool mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] )
( reference )
Beware though that the underlying mail transport service may or may not allow arbitrary addresses in these fields.
It's also very easy to screw the message format with mail()
so I strongly recommend a third party library like Swift Mailer or PHPMailer .
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.