By supportsit
Help me please! When sending email messages php script in the browser worked through about 2 minutes, but all messages are delivered. there are no errors on other SMTP servers is the same
PHP code
date_default_timezone_set('Europe/Kiev');
require_once($_SERVER['DOCUMENT_ROOT'].'/engine/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->isSMTP();
//хост
$mail->Host = 'smtp.mail.ru';
$mail->SMTPAuth = true;
$mail->Username = 'admin@example.com';
$mail->Password = '********';
$mail->SMTPSecure = 'ssl';
$mail->Port = '465';
$mail->debug = true;
$mail->CharSet = 'UTF-8';
$mail->From = 'admin@example.com';
$mail->FromName = 'Админ';
$mail->addAddress('mail@example.com');
$mail->isHTML(true);
$mail->Subject = 'Тест Темы письма';
$mail->Body = 'тестовый текс Текст можно с хтмл';
if( $mail->send() ){
echo 'Письмо отправлено';
}else{
echo 'Письмо не может быть отправлено. ';
echo 'Ошибка: ' . $mail->ErrorInfo;
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This comment has been deleted
One possible reason for this type of delay is if mail.ru defaults to ipv6 as gmail does PHPMailer will first attempt to reach the SMTP service by it’s ipv6 address. Whle we provide ipv6 support if you enable it on your droplet we do not allow SMTP traffic over ipv6 so this first attempt would be blocked. Trying the ipv4 address would then connect successfully.
Try replacing this:
$mail->Host = 'smtp.mail.ru';
with this, in your script
$mail->Host = gethostbyname("smtp.mail.ru");
If the issue is an ipv6 attempt it should then be resolved. If you continue to see these long waits after this change, let us know here.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.