у меня есть этот код функции
require_once("../includes/classMail/class.smtp.php");
require_once("../includes/classMail/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = $_SESSION['MailHost']; // SMTP servers
// sender
$mail->From = $_SESSION['UserEmail'];
$mail->FromName = $_SESSION['UserName'];
// receiver
unset($ArrExp);
$ArrExp=explode(",",$EmailTo);
for ($i=0;$i<count($ArrExp);$i++) {
$mail->AddAddress($ArrExp[$i],"");
}
if($EmailCC!="")
{
// CC to
unset($ArrExp);
$ArrExp=explode(",",$EmailCc);
for ($i=0;$i<count($ArrExp);$i++) {
$mail->AddCC($ArrExp[$i],"");
}
}// ReplyTo
$mail->AddReplyTo("$_SESSION[UserEmail]","$_SESSION[UserName]");
// attachement File
$TxtAttach=explode("{:}",$TxtAttach);
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("../images/logoletter/$EmailAttach"); // attachment1
for ($i=0;$i<count($TxtAttach);$i++)
{
$TxtAttach2=explode("{..}",$TxtAttach[$i]);
// attachment2
$mail->AddAttachment("../upload/$TxtAttach2[0]");
}
$mail->IsHTML(true); // send as HTML
$mail->Subject = $EmailSubject;
$mail->Body = $EmailBody;
$mail->AltBody = "";
if(!$mail->Send())
{
return $mail->ErrorInfo;
} else {
return 1;
}
эта функция отлично работает для почты моей компании, но я не могу отправить ее на почту gmail / yahoo, используя эту функцию, и никаких ошибок не появляется
Как я могу это исправить, чтобы я мог отправить почту на Gmail / Yahoo или другую почту. Спасибо
Я думаю, что вам нужно определить ваш хост, т.е. $ mail-> Host = ‘smtp.gmail.com’ и номер порта. $ mail-> Port = 465.или пожалуйста код ниже.
<?php
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "test3123";
$mail->setFrom('[email protected]', 'development'); //add sender email address.
$mail->addAddress('[email protected]', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Других решений пока нет …