Rajesh
Rajesh

Reputation: 195

PHPMailer with SMTP details

I would like to send mail from my php form. Initially I had used php mail function and it was working fine. But I recently shifted my server from windows to Linux in which SMTP is mandatory. I am not given access to php.ini file. Hence I am using phpMailer function. But when I use phpMailer, it gives me the following error

Invalid address: (punyEncode) abc-domain Mailer Error: Invalid address: (punyEncode) abc-domain.

My username is not my mail address i.e., [email protected] but it is abc-domain. Here is my code. I have PHPMailer files in a folder called PHPMailer.

<?php
require('PHPMailer/PHPMailerAutoload.php');

$mail = new PHPMailer;

$mail->CharSet = "UTF-8"; 


$mail->SMTPDebug = 3;                               

$mail->isSMTP();            

$mail->Host = "mail.abc.com";

$mail->SMTPAuth = true;                          

$mail->Username = "abc-domain";                 
$mail->Password = "abc123";                           

$mail->Port = 25;                                   

$mail->From = "abc-domain";
$mail->FromName = "Webmaster-Domain";

$mail->addAddress("[email protected]", "xyz");

$mail->isHTML(true);

$mail->Subject = "Subject Text";


$mail->Body = '<h1 style="font-family: Arial;">HTML Text</h1>';

if(!$mail->send()) 
{
    $mail->SMTPDebug = true;
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo $success;
}
?>

Is there a way to setup SMTP details through .htaccess?

Upvotes: 1

Views: 505

Answers (1)

Samuel Aiala Ferreira
Samuel Aiala Ferreira

Reputation: 694

The problem is here

$mail->From = "abc-domain";

It should be a valid email, even if you user isn't (which is ok, because you only need it here $mail->Username)

Upvotes: 3

Related Questions