0

次のコードは私のウェブサイトから電子メールを送信していますが、電子メールは から送信されています。cgi-mailer@kundenserver.de変数を指定した送信者の電子メール アドレスに変更するにはどうすればよいですか$email

<?php
if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
    mail('me@example.com', 'Message from website', $msg );
    header('location: contact-thanks.php');

    } else {
header('location: contact.php');
exit(0);
}
?>

メールコマンドにヘッダーを追加するFrom:と、メールアドレスを変更できるようですが、変数に変更する方法がわかりません。

4

4 に答える 4

2
<?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.";

?>

詳細については

http://php.net/manual/en/function.mail.php

于 2012-12-19T10:10:59.427 に答える
2

ヘッダーで変数を宣言します。

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

編集:

<?php
if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
$headers = 'From: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    mail('me@example.com', 'Message from website', $msg, $headers );
    header('location: contact-thanks.php');

    } else {
header('location: contact.php');
exit(0);
}
?>
于 2012-12-19T10:08:31.760 に答える
0

これをヘッダーに追加します

$headers .= 'From: ' . $from . "\r\n";
$headers .='Reply-To: $from' . "\r\n" ;
mail($to,$subject,$message,$headers);

送信者を設定する必要があります。

どこ

$from= "Marie Debra <marie.debra@website.com>;"
于 2012-12-19T10:08:38.360 に答える