我在PHPMailer中的地址驗證器中遇到問題。有人可以幫我一個有效的嗎?我的PHP版本是5.6.19,而PHPMailer的版本是5.2.16,所以基本上選擇的庫是pcre8。弱小編碼:PHPMailer版本5.2.16和PHP版本5.6.19的有效PCRE8庫
return (boolean)preg_match(
'/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
'((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
'(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
'([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
'(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
'(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
'|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
'|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
$address
);
send.php:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
require_once('class.phpmailer.php');
$to=isset($_POST['verify'])?$_POST['verify']:false;
$subject="Email verification";
$message='<p>Welcome to Our service this is an email verification procedure, Please click <a href="#">here</a> to go back.';
//$to= "[email protected]";
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
// SMTP Configuration
$mail->SMTPSecure='ssl';
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.gmail.com "; // SMTP server
$mail->Username = "[email protected]";
$mail->Password = "mypassword";
$mail->Port = 465; // optional if you don't want to use the default
$mail->From = "<[email protected]>";
$mail->FromName = "Admin";
$mail->Subject = $subject;
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->isHTML(true);
$mail->Body=$message;
$mail->msgHTML($message);
$mail->addAddress($to);
if(!$mail->Send())
{
$response = "Message error!".$mail->ErrorInfo;
echo $response;
// echo $to;
}
else {
$response = "Message sent!";
echo $response;
}
?>
謝謝!
這是相當正確的。您是否看過其他一些關於使用PHP驗證電子郵件的主題? http://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php – chris85
這不是關於使用正則表達式驗證電子郵件地址的一般問題;它關於PHPMailer中的驗證機制。 – Synchro
@Synchro這是怎樣的不同? PHPMailer似乎使用正則表達式進行驗證,並且問題實際上是要求爲此驗證提供有效的正則表達式。 –