Vignesh Bala
Vignesh Bala

Reputation: 663

SMTP Error on sending mail

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...

Upvotes: 1

Views: 6282

Answers (2)

Naz Mir
Naz Mir

Reputation: 1028

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);

?>

Upvotes: 3

caskey
caskey

Reputation: 12695

Your mail server requires authentication (username + password) before it will accept email from you. It is suggesting you either provide it via your SMTP connection (using SMTP AUTH, hopefully with TLS), or that you do a technique called POP before SMTP where you first login and 'check' your mail which will cause a temporary whitelisting of your host so it can send mail for a brief while afterward.

Upvotes: 2

Related Questions