PHP邮件程序在发送第二封电子邮件后未验证

时间:2014-01-20 20:49:39

标签: php validation email phpmailer

这是一个更新的消息,带有使用php邮件发送两个不同电子邮件的工作代码。它还有工作验证服务器站点。

您需要创建自己的邮件类或使用正常邮件类。

希望别人可以使用它两个!

谢谢!

<?php

require"validation.php";

  ob_start();

  $name      = trim($_POST['name']);
  $email     = $_POST['email'];
  $comments  = $_POST['comments'];
  $info_email= 'example@example.com';
  $info_name = 'Example';


require"PHPMailer/mail.inc.php";

$cams="$name has just made a comment or posted a question";
$camb= "<html> 

<head>
<h3> $name has  asked the following question or comment on you website:</h3>
</head>
<body>

$comments <br><br><br>

Their information: <br><br>

<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\">

 <tr>
  <td align=\"center\">Name:</td>
  <td align=\"center\"> $name</td>
  </tr>
<tr>
  <td align=\"center\">Email:</td>
  <td align=\"center\"> $email</td>
  </tr>
</table>
<br>

<img src=\"cid:mailhead\" alt=\"shop logo used in emails\"  />

Pleasy try to reply as soon as possible.<br>
Thank you!!

</body>
</html>";

$mail = new MailCon;
$mail->IsSMTP();     
$mail->isHTML(true); 

$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($info_email, $info_name);

$mail->Subject = $cams;
$mail->MsgHTML($camb);

if ($mail->Send()) {

$mail->ClearAllRecipients(); 
  $mail->ClearReplyTos();
  $mail->ClearCustomHeaders();

  $cums = 'Thank you for using our contact form.';


  $message = file_get_contents('mail/example.html'); 
    $message = str_replace('%username%', $name, $message); 
    $message = str_replace('%email%', $email, $message); 
    $message = str_replace('%comments%', $comments, $message); 

$alt_body="Thank you for asking us a question or making a comment. We will reply as soon as possible.";

  $mail = new MailCon;
  $mail->IsSMTP();
  $mail->IsHTML(true);      

  $mail->From = $info_email;
  $mail->FromName = $info_name;
  $mail->AddAddress($email, $name);  // Add a recipient 



  $mail->Subject = $cums;
  $mail->MsgHTML($message);
  $mail->AltBody = $alt_body;
  $mail->Send(); 

}

ob_end_flush();

?>

这是您可以使用require一次包含的验证位。

 <?php

 $name      = trim($_POST['name']);
  $email     = $_POST['email'];
  $comments  = $_POST['comments'];

  if (strlen($name) < 2) {
$error['name'] = "Please enter your name";  
  }

  if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is',     $email)) {
$error['email'] = "Please enter a valid email address"; 
  }

  if (strlen($comments) < 3) {
$error['comments'] = "Please leave a comment.";
  }

  if (!$error) {

 echo "<div class='alert-box success'>Thanks " . $name . ". Your message has        been sent.<a href='' class='close' onclick='clearForms()'>&times;</a></div>";

  } # end if no error
  else {

 $response = (isset($error['name'])) ? "<div class='alert-box alert'>" . $error['name'] . "</div> \n" : null;
    $response .= (isset($error['email'])) ? "<div class='alert-box alert'>" . $error['email'] . "</div> \n" : null;
    $response .= (isset($error['comments'])) ? "<div class='alert-box alert'>" . $error['comments'] . "</div>" : null;

    echo $response;

  exit();

  } # end if there was an error sending

  ?>

0 个答案:

没有答案
相关问题