0

我正在使用这个脚本 http://www.quackit.com/html/codes/html_form_to_email.cfm

默认情况下效果很好。

但我添加了一些额外的变量,例如:

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$namn = $_REQUEST['namn'] ;
$telefonnummer = $_REQUEST['telefonnummer'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

我的问题是我无法让它们出现在发送的电子邮件中。

我试过像这样包含它们:

mail( "$webmaster_email", "Feedback Form Results",
  $namn, $email, $telefonnummer, $comments, "From: $email_address" );

和这个:

mail( "$webmaster_email", "Feedback Form Results",
  $comments, "From: $email_address" );
  $email, ;)
  $telefonnummer, :)

它不工作,你知道我做错了什么吗?

4

3 回答 3

0

mail()您的代码与定义不符:http: //php.net/manual/en/function.mail.php

你应该有:

mail( $webmaster_email, "Feedback Form Results", "$namn, $email, $telefonnummer, $comments", "From: $email_address" );
于 2013-01-08T19:22:30.163 回答
0

看一下mail()函数,它接受四个参数

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

所以你应该改变你的代码,让它看起来像这样,考虑到你在添加这些新字段的表单中做的一切都很好

$message=$namn.','. $email.','. $telefonnummer.','. $comments;
mail( $webmaster_email, "Feedback Form Results",  $message, "From: {$email_address}" );

此外,您可能需要在标题(第四个参数)中添加一些附加信息,以便您的消息正确显示,以防它里面有一些 html,看看这个来自 php.net 的例子

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

 // Mail it
 mail($to, $subject, $message, $headers);
于 2013-01-08T19:28:44.937 回答
0

您需要查看PHP 邮件。你有很多参数。

基本用法是:mail($to, $subject, $message, $additional_headers);

尝试:

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$namn = $_REQUEST['namn'] ;
$telefonnummer = $_REQUEST['telefonnummer'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

$message = 'namn: ' . $namn . ' telefonnummer: ' . $telefonnummer . ' email_address: ' . $email_address . ' comments: ' . $comments;

mail($webmaster_email, "Feedback Form Results", $message, "From: $email_address");
于 2013-01-08T19:31:01.797 回答