I want to send a letter to PHPMailer. I am using this code, but I got this error:
Invalid address: example@gmail.com
(I use fake addresses for StackOverflow. I use a real address in my real code.)
<?php
$from = "My Name";
$mail = "example@gmail.com";
require_once('./class.phpmailer.php');
$bodytext = "
<html>
<head>
<title>title</title>
</head>
<body>
<h1 style='text-align:center'>Some text</h1>
<p>more text. Here a name : $from</p>
</body>
</html>
";
try {
$email = new PHPMailer(true);
$email->From = 'webmaster@mysite.com';
$email->FromName = 'WebMaster';
$email->isHTML(true);
$email->Subject = 'subject';
$email->Body = $bodytext;
$email->addAddress( $mail, "Name" );
$email->AddReplyTo($mail,"Name");
$email->Send();
} catch (Exception $e) {
echo $e->getMessage();
}
?>
Sice already has an SMTP server, I don’t need to configure it, and the PHP function works mail.
How can I fix this error?
source
share