Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件程序脚本帮助_Php_Email - Fatal编程技术网

PHP邮件程序脚本帮助

PHP邮件程序脚本帮助,php,email,Php,Email,我对PHP一无所知,我有一个脚本可以通过电子邮件发送表单内容。问题是,它只在我希望它同时发送所捕获的姓名和电子邮件地址时才向我发送评论 有人知道我如何调整这个脚本来做到这一点吗 万分感谢 <?php error_reporting(E_NOTICE); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6

我对PHP一无所知,我有一个脚本可以通过电子邮件发送表单内容。问题是,它只在我希望它同时发送所捕获的姓名和电子邮件地址时才向我发送评论

有人知道我如何调整这个脚本来做到这一点吗

万分感谢

<?php
 error_reporting(E_NOTICE);
 function valid_email($str)
 {
  return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
 }
 if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
 {
  $to = "me@me.com";
  $headers =  'From: '.$_POST['email'].''. "\r\n" .
    'Reply-To: '.$_POST['email'].'' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
  $subject = "Contact Form";
  $message = htmlspecialchars($_POST['comment']);
  if(mail($to, $subject, $message, $headers))
  {
   echo 1; //SUCCESS
  }
  else {
   echo 2; //FAILURE - server failure
  }
 }
 else {
  echo 3; //FAILURE - not valid email
 }
?>

你可以这样做

$extra_fields = 'Name: '.$_POST['name'].'<br>Email: '.$_POST['email'].'<br><br>Message:<br>';
$message = $extra_fields.$_POST['comment'];
$extra\u fields='Name:'.$\u POST['Name'].
电子邮件:'.$\u POST['Email'.'.

消息:
; $message=$extra_字段。$_POST['comment'];
不是很干净,但你明白了。只需将数据与$message连接起来。

更改此行:

  $message = htmlspecialchars($_POST['comment']);


或者类似的问题是你的
$message=…
行,它只包括
$\u POST['comment'])
变量。您需要添加
$\u POST['name']
$\u POST['email']
,如下所示:

$message = '';
$message .= htmlspecialchars($_POST['name']) . "\n";
$message .= htmlspecialchars($_POST['email']) . "\n";
$message .= htmlspecialchars($_POST['comment']) . "\n";
$message = '';
$message .= htmlspecialchars($_POST['name']) . "\n";
$message .= htmlspecialchars($_POST['email']) . "\n";
$message .= htmlspecialchars($_POST['comment']) . "\n";