【问题标题】:Web Form With Smtp Authentication (reply-to)带有 Smtp 身份验证的 Web 表单(回复)
【发布时间】:2012-11-24 03:48:11
【问题描述】:

我的联系表格来自 TEST - 如下面的代码所示,但我需要它来自填写表格的人,以便在回复电子邮件时,它会发送到输入的地址,而不是 TEST。

我是 PHP 新手,能否在实现回复时寻求帮助?我已经尝试过并且一直缺少一些东西。

这是我的原始代码。谢谢!

<?php
if(isset($_POST['email'])) {

function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['contact_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');   
}

$contact_name = $_POST['contact_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$comments = $_POST['comments']; // not required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "/^[A-Za-z 0-9.'-]+$/";
  if(!preg_match($string_exp,$contact_name)) {
$error_message .= 'The Contact Name you entered does not appear to be valid.<br />';
  }
   if(!preg_match($string_exp,$telephone)) {
$error_message .= 'The Telephone # you entered does not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
died($error_message);
  }
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Contact Name: ".clean_string($contact_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";

ini_set('display_errors',1);
error_reporting(E_ALL); 

  require_once "Mail.php";

$from = "TEST<todd@xxxxxx.com>";
$to = "<anyone@xxxxxxxx.com>";
$subject = "Test message";
$body = "$email_message";

$host = "mail.xxxxxxxx.com";
$username = "todd@xxxxxxxx.com";
$password = "xxxxxxxxxx";

headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p></p>");
}
?>


<!-- include your own success html here -->
message sent

<?php
}
?> 

【问题讨论】:

    标签: php email send


    【解决方案1】:

    试试:

    $from = $_POST['contact_name'];
    

    或者,如果您希望显示他们的电子邮件:

    $from = $_POST['email'];
    

    【讨论】:

    • 谢谢。但由于 SMTP 身份验证,此 $from 必须来自 TEST 地址。这就是为什么我必须设置回复,但由于我缺乏 PHP 知识,我无法正确编程。我正在应对并寻求实施回复的帮助。
    猜你喜欢
    • 2012-04-17
    • 2010-10-27
    • 2015-04-29
    • 2015-01-10
    • 2014-07-05
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 2016-01-09
    相关资源
    最近更新 更多