简体   繁体   English

SMTP邮件无法在服务器上正常工作在本地主机上

[英]SMTP Mail Not Working ON Server Working Fine On Localhost

Hi i am using smtp latest files and check all the solution availble on net, My SMTP php mail working on localhost not working on server my server's web mail working Fine.First of all i am inserting data into my database then those data i want to sent admin email id my data are inserting in database also mail sending working fine on localhost but given error on server it give's failed to connect with server. 嗨,我正在使用smtp最新文件,并检查网上所有可用的解决方案,我在本地主机上运行的SMTP php邮件在服务器上不起作用,我的服务器的网络邮件正常工作。首先,我将数据插入数据库,然后将这些数据插入数据库发送了管理员电子邮件ID,我的数据正在数据库中插入,邮件也在localhost上正常工作,但是由于服务器上出现错误,它无法与服务器连接。 i contact with my hosting server support forum but they are saying this your code problem Here is my PHP Code 我与我的托管服务器支持论坛联系,但他们说的是您的代码问题,这是我的PHP代码

 <?php
   if(isset($_POST['Isubmit'])){
   $rname= $_POST['Iname'];
   $remail= $_POST['Iemail'];
   $rcontact= $_POST['Icontact'];
   $rmessage= $_POST['Icomment'];
   $rcourse= $_POST['Icourse'];
    $date=date("Y-m-d");
 $sql=mysqli_query($connect,"INSERT INTO enquiry(`NAME`,`EMAIL_ID`,`MOBILE_NO`,`COMMENT`,`SUBJECT`,`IS_DELETED`,`DATE`)VALUES('".$rname."','".$remail."','".$rcontact."','".$rmessage."','".$rcourse."','1','".$date."')");

//Mail Send Code


 $ToEmail = 'admin@gmail.com'; 
 $EmailSubject = 'Site contact form'; 
 $MESSAGE_BODY = "Dear Sir/Mam,"."\n" ."\n"."New Contact Details are - "."\n"."\n"; 
$MESSAGE_BODY .= "Full Name: ".$rname."\n"."\n"; 
$MESSAGE_BODY .= "Email: ".$remail."\n"."\n"; 
$MESSAGE_BODY .= "Phone: ".$rcontact."\n"."\n"; 
$MESSAGE_BODY .= "Message: ".$rmessage."\n"."\n";
$MESSAGE_BODY .= "Course: ".$rcourse."\n"."\n";
 //SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don'thave access to that date_default_timezone_set('Etc/UTC');
       require 'PHPMailer-master/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)
    $mail->SMTPDebug = 0;
 //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 = "username@gmail.com";//"lino.cspace@gmail.com";
   //Password to use for SMTP authentication
    $mail->Password = "yourpassword";//"lino@123";
      //Set who the message is to be sent from
       $mail->setFrom('admin@gmail.com', 'Admin');
       $mail->addAddress($ToEmail);
      //Set the subject line
        $mail->Subject = 'Enquiry Mail';
       $mail->Body = $MESSAGE_BODY;//'this is test msg on 25-jun.';
       if(!$mail->Send()) {
         echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
           echo "Message sent!<br>";
          }
       }

Enable smtp debugging 启用S​​MTP调试

$mail->SMTPDebug = 1;

OR 要么

 $mail->SMTPDebug = 2;

Then the error info will give you more info on the error 然后错误信息将为您提供有关错误的更多信息

if (!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message sent!<br>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CodeIgniter邮件无法在服务器上运行,但可以在本地主机上正常工作 - CodeIgniter mail not working on server but works fine localhost 本地主机上的PHP mail()与Comcast的SMTP服务器不起作用 - PHP mail() on localhost with Comcast's SMTP Server not working 在服务器中通过gmail smtp发送邮件时出现问题,但在localhost中工作正常 - problem in sending mail by gmail smtp in server but works fine in localhost Phpmailer 在 localhost 中工作正常但不在服务器中 - Phpmailer working fine in localhost But not in server fullcalendar在localhost中工作正常,但在服务器中工作不正常 - fullcalendar is working fine in localhost but not in server 会话在本地主机上工作正常但在服务器上不工作 - Session in working fine in localhost but not at server 邮件功能在localhost服务器中不起作用 - mail function is not working in localhost server $ .post和AJAX不能在服务器上运行,但在localhost中工作正常 - $.post & AJAX is not working on server, but working fine in localhost imap无法从实时服务器连接到邮件服务器,但可以从本地主机正常工作 - imap is not connecting to mail server from live server but working fine from localhost 使用 Laravel,SMTP 邮件在 Live Server 中不起作用 - Using Laravel, SMTP Mail not Working in Live Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM