PHP - 将表单输入的副本发送给用户

时间:2015-07-14 20:38:06

标签: php email

我试图将提交的表单的副本发送给客户端的用户。我尝试实现我已经在这里找到的一些代码,但无法使其成功运行。你们介意看看吗? ...一如既往地赞赏所有投入!

""

2 个答案:

答案 0 :(得分:2)

首先,您需要声明变量,然后发送电子邮件:

    // validation expected data exists

$error_message = "";
//get fields, and check if they are filled
$project_name = $_POST['first_name'];
required_field($project_name,"Project Name");

$last_name = $_POST['last_name'];
required_field($last_name,"Last Name");

$email_from = $_POST['email'];
required_field($email_from,"Email");

$contact_reason = $_REQUEST['contact_reason'];

$other_info = $_POST['other_info'];
required_field($other_info,"Additional Info"); 

//phone number manip
$phone_number_clean = clean_phone_number($phone_number);

//email manip
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "nonedesigns@gmail.com";
$email_subject = "SuitUP | Support";
$success = mail($email_to, $Subject, $Body, "From: <$email_from>");

if ($success)
    mail($email_from, $Subject, $Body, "From: <$email_from>");

尝试在变量命名约定中保持一致(不混合CamelCase和下划线)。这将使您更容易掌握代码。

答案 1 :(得分:2)

尝试使用PHPMailer发送邮件。尝试下面的标准PHP代码,但首先下载phpmailer.php并保存。

// include the PHPMailer
 require_once('PHPMailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$mail->IsSendmail(); // telling the class to use SendMail transport

$body             = "hello";

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$address = "name@yourdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->Subject    = "PHPMailer Test Subject via Sendmail, basic";

$mail->AltBody    = "To view the message, please use an HTML compatible         email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->IsHTML(true);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!"; 
}