Reputation: 151
I am trying to send mail using PHPMailer and my code looks like this.
require 'inc/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$mail->isSendmail();
$mail->setFrom($email, $name);
$mail->addAddress('examp@gmail.com', 'example');
$mail->Subject = 'PHPMailer sendmail test';
$mail->msgHTML($email_body);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error is: " . $mail->ErrorInfo;
exit;
} else {
echo "Message sent!";
}
But it is showing error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\class.phpmailer.php on line 1134
I have downloaded by PHPMailer from https://github.com/Synchro/PHPMailer
Upvotes: 0
Views: 176
Reputation: 244
This probably happends because phpmailer is validating the email address...
Solution 1: Because you entered the email address yourself you could replace the following function in class.phpmailer.php
:
public static function ValidateAddress($address) {
if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) {
return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?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][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
} elseif (function_exists('filter_var')) { //Introduced in PHP 5.2
if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
return false;
} else {
return true;
}
} else {
return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
}
}
with:
public static function ValidateAddress($address) {
return true;
}
Solution 2: This is the easiest way to fix it (probably). Paste the following line at the top of your code.
set_time_limit(60); //60 seconds = 1 minute
Solution 3: Try this: How to correctly fix phpMailer max execution time error? (Idk if this actually works.)
EDIT: You also forgot the: $mail->isHTML(true);
Upvotes: 1
Reputation:
$mail->isHTML(true);
$mail->Subject = 'PHPMailer sendmail test';
$mail->Body = $email_body;
Upvotes: 0