Phpmailer: phpmailer invalid address (punyEncode) root@localhost

Created on 27 Oct 2017  Â·  13Comments  Â·  Source: PHPMailer/PHPMailer

I'm just try tp use but i got Error "invalid address (punyEncode) root@localhost"
$mail = new PHPMailer(true);
try{
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = '*@gmail.com';
$mail->Password = ' *
* ';
$mail->SetFrom = ('[email protected]');
$mail->Subject = 'Test sending mail';
$mail->Body = 'My Body & My Description';
$mail->AddAddress('[email protected]');
$mail->send();
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}

How can i solve this?

Most helpful comment

Did you copy this code from an example? If yes, please give the reference, so it can be fixed.

$mail->SetFrom = ('[email protected]');

This is incorrect usage of SetFrom. It is a method, but your code treats it as a variable. Replace with:

$mail->SetFrom('[email protected]');

All 13 comments

Did you copy this code from an example? If yes, please give the reference, so it can be fixed.

$mail->SetFrom = ('[email protected]');

This is incorrect usage of SetFrom. It is a method, but your code treats it as a variable. Replace with:

$mail->SetFrom('[email protected]');

Thank you so much.

Try reading your own code?

$mail->setFrom = $webmaster_email;

You have not set a value for $webmaster_email, so it generates a default From address from your PHP config. Solution: set it properly.

I would suggest you to change your password because I myself tempted to enter in your email and who knows what else ...

(<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require "vendor/autoload.php";

if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])){
    $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
    $email = $_POST['email'];
    $message = $_POST['message'];

    $mail = new PHPMailer(true);                          
    $mail->isSMTP();
    $mail->SMTPDebug = 2;
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth = true;
    $mail->Username = "[email protected]";
    $mail->Password = "****";
    $mail->setFrom = $email ;
    $mail->addAddress('[email protected]', 'Istiyak Amin');
    $mail->isHTML(true);                                  
    $mail->Subject = 'Got one new messege from your website';
    $mail->Body    = '<b>name: </b>' . $name . '<br>' . '<b>Email: </b>' . $email . '<br>' . '<b>Message: </b>' . $message;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();

    header('Location: ' . $_SERVER['HTTP_REFERER']);


} 

else header('location: http://istiyak.xyz/#contact');
)

**Invalid address: (From): root@localhost

Fatal error: Uncaught PHPMailer\PHPMailer\Exception: Invalid address: (From): root@localhost in /home/worldspo/istiyak.xyz/vendor/phpmailer/phpmailer/src/PHPMailer.php:1428 Stack trace: #0 /home/worldspo/istiyak.xyz/vendor/phpmailer/phpmailer/src/PHPMailer.php(1348): PHPMailer\PHPMailer\PHPMailer->preSend() #1 /home/worldspo/istiyak.xyz/sendMail.php(29): PHPMailer\PHPMailer\PHPMailer->send() #2 {main} thrown in /home/worldspo/istiyak.xyz/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1428**

  1. You made the same mistake as the original poster. Read again this thread. You should write $mail->setFrom($email);.
  2. Remove your password from your code snippet.

codicemail
Invalid address: (From): root@localhost

Pahele php mailer ki Error sahi karle bhai

On Sat, 22 Dec 2018 16:25 Mugna00 <[email protected] wrote:

[image: codicemail]
https://user-images.githubusercontent.com/46057469/50373498-4205cb80-05e0-11e9-9636-07155f46fce6.png
Invalid address: (From): root@localhost

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPMailer/PHPMailer/issues/1212#issuecomment-449562129,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYpwek0XvwGp74O9wrv3CT3xx-8uCGSIks5u7g-SgaJpZM4QJKCB
.

The foul example code is posted at cloudways.com.
I left them a comment, hope they fix it.

$mail->setFrom([email protected]);
or
$mail->setFrom($webmaster_email);

this fix your error

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Base files
//require 'PHPMailer/src/Exception.php';
//require 'PHPMailer/src/PHPMailer.php';
//require 'PHPMailer/src/SMTP.php';

// create object of PHPMailer class with boolean parameter which sets/unsets exception.

$mail = new PHPMailer(true);

try {

//server settings...
$mail->SMTPDebug = 2;
$mail->isSMTP(); // using SMTP protocol     

$mail->Host = 'smtp.gmail.com'; // SMTP host as gmail 
$mail->SMTPAuth = true;  // enable smtp authentication                             
$mail->Username = '[email protected]';  // sender email             
$mail->Password = '09075928834'; // sender email  password                          
$mail->SMTPSecure = 'tls';  // for encrypted connection                           
$mail->Port = 587;   // port for SMTP     
$mail->SMTPOptions = array(
            'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
            )
);

//recipients..
$mail->setFrom("[email protected]", "Tutme"); // sender's email and name
$mail->addAddress($email, $firstname);  // receiver's email and name
//$mail->addReplyTo('[email protected]');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]'); // if add email recipeints will not no that a copy is send

//contents..
$mail->isHTML(true);
$mail->Subject = 'Tutme Account Verification';
$mail->Body    = $msg;
//convert HTML into a basic plain-text alternative body..
//$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//$mail->AltBody    = "Every thing is possible in this world"; // for non-html mail clients.

// Attachments

// $mail->addAttachment("img.jpg);
// $mail->addAttachment("img2.jpg, kkk.jpg);
$mail->send();

header("Location: thankyou.php");

}catch (Exception $e)
{
// handle error.
echo "having some issues sending mail. Mailer Error: {$mail->ErrorInfo}";
}

then i get this error...
Invalid address: (to):

This may come as a shock, but that error will be because your to address is invalid.

Thank you.... I have resolved the issue

On Sun, Dec 13, 2020, 22:19 Marcus Bointon notifications@github.com wrote:

This may come as a shock, but that error will be because your to address
is invalid.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPMailer/PHPMailer/issues/1212#issuecomment-744070109,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AIU6B3E34E32UAXDSEELBITSUUVUXANCNFSM4EBEUCAQ
.

Was this page helpful?
0 / 5 - 0 ratings