duanfu2562 2013-09-05 06:28
浏览 901
已采纳

SMTP发送邮件时出错

I have been trying to send mail using wamp server in my laptop. The SMTP server is presented in online. Here is my php code to send mail:

<?php
        ini_set( 'SMTP', "mail.vickey1192.co.in" );
        ini_set( 'smtp_port', 26 );
        ini_set( 'sendmail_from', "admin@vickey1192.co.in" );

        $to = "balavickey1192@gmail.com";
        $subject = "Acknowledgement";
        $message = "Thank you for registering with us<br>";
        $from = "no-reply@vickey1192.co.in";
        $headers = "From:" . $from;

        mail($to,$subject,$message,$headers);
        echo "Mail Sent.";
?>

I also set my php.ini file like this:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.vickey1192.co.in
; http://php.net/smtp-port
smtp_port = 26

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = admin@vickey1192.co.in

This is the error I am getting:

Warning: mail() [function.mail]: SMTP server response: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. (vignesh-PC) 550-[115.118.170.201]:23328 is not permitted to relay through this server 550 without authentication. in C:\wamp\www\mailtofunc.php on line 12

What do I do now? Please help me guys...

  • 写回答

2条回答 默认 最新

  • dongqiang8474 2013-09-05 06:46
    关注

    I think its a problem with authentication. You need to add the SMTP user's username and password to the mail function to send the email.

      //Using built in mail method
      $mail = new PHPMailer();
      $mail->Host = 'smtp.example.com'
      $mail->SMTPAuth = true;     // turn on SMTP authentication
      $mail->Username = 'your_username@example.com';  // a valid email here
      $mail->Password = 'replace_with_your_password';
      $mail->From = 'from@example.com';
      $mail->AddReplyTo('from@example.com', 'Test');
    
      $mail->FromName = 'Test SMTP';
      $mail->AddAddress('test1@example.com', 'test2@example.com');
    
      $mail->Subject = 'Test SMTP';
      $mail->Body = 'Hello World'; 
    
      $mail->Send();
    

    You might be better off trying the PHP's Pear mail function, if you know how to use it.

    //Using PEAR's mail function
    <?php
      include('Mail.php');
    
      /* mail setup recipients, subject etc */
      $recipients = "your_recipients@example.com";
      $headers["From"] = "user@example.com";
      $headers["To"] = "feedback@example.com";
      $headers["Subject"] = "Some Subject";
      $mailmsg = "Hello, This is a test.";
    
      /* SMTP server name, port, user/passwd */
      $smtpinfo["host"] = "smtp.example.com";
      $smtpinfo["port"] = "25";
      $smtpinfo["auth"] = true;
      $smtpinfo["username"] = "smtpusername";
      $smtpinfo["password"] = "smtpPassword";
    
      /* Create the mail object using the Mail::factory method */
      $mail_object =& Mail::factory("smtp", $smtpinfo);
    
      /* Ok send mail */
      $mail_object->send($recipients, $headers, $mailmsg);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!