PHPMailer 6 Contact Form with Gmail SMTP - php

I'm trying to make it so that emails can be sent to my Gmail address rather than my domain name email using a PHPMailer form that is in a Bootstrap website. That is my main goal, and the other is to figure out how to have the form include the person's name, email and a subject populate the email rather than the set subject and "no-reply" email. Any help I could get on this would be great; I thought I would see if anyone wanted to solve this for the community here before I hire a freelancer. Thanks!!
I've tried several tutorials to solve this as well as trying to combine the existing code I'm posting below with the SMTP Gmail version on the PHPMailer Github page ( https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps )but I was not successful, I would instead post the working code here to my domain name email than my failed attempts at sending to Gmail.
<form id="contact-form" method="post" action="contact.php">
<div class="messages"></div>
<div class="controls">
<div class="form-group">
<input id="form_name" type="text" name="name" class="form-control" placeholder="Enter your name." required="required">
</div>
<div class="form-group">
<input id="form_email" type="email" name="email" class="form-control" placeholder="Enter your email." required="required">
</div>
<div class="form-group">
<textarea id="form_message" name="message" class="form-control" placeholder="Add your message." rows="4" required="required"></textarea>
</div>
<input type="submit" class="btn btn-outline-light btn-sm" value="Send message">
</div>
</form>
<?php
use PHPMailer\PHPMailer\PHPMailer;
require './PHPMailer-master/vendor/autoload.php';
$fromEmail = 'noreply#email.com';
$fromName = 'No Reply Email';
$sendToEmail = 'name#mydomain.com';
$sendToName = 'New Website Email Message';
$subject = 'New message from contact form';
$fields = array('name' => 'Name:', 'email' => 'Email:', 'message' => 'Message:');
$okMessage = 'Successfully submitted - we will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailTextHtml .= "<h3>New message from website:</h3><hr>";
$emailTextHtml .= "<table>";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailTextHtml .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
}
}
$emailTextHtml .= "</table><hr>";
$emailTextHtml .= "<p>Have a great day!</p>";
$mail = new PHPMailer;
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($sendToEmail, $sendToName);
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->Subject = $subject;
$mail->Body = $emailTextHtml;
$mail->isHTML(true);
if(!$mail->send()) {
throw new \Exception('Email send failed. ' . $mail->ErrorInfo);
}
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
?>

It is working on my projects. You can also remove the part of the code which you don't need like attachments. One more thing if you want to hide the debugging code errors and notifications remove or comment this line $mail->SMTPDebug = 2.
Check this similar StackOverflow article for more help
If you still need more help to let me know.
Hope this may help you.
<?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 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}`enter code here`
s

This is what I use for my form mail, change the variables accordingly.
// PHPMailer
require '/var/www/...../PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "abcdefgh#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "pppppppppppppppp";
//Set who the message is to be sent from
$mail->setFrom($Email, $Name);
//Set an alternative reply-to address
$mail->addReplyTo($Email, $Name);
//Set who the message is to be sent to
$mail->addAddress('myemailaddress#gmail.com', 'Form Mail');
//Set the subject line
$mail->Subject = 'Form Mail";
// END PHP Mailer
$mail->ContentType = 'text/plain';
$mail->isHTML(false);
// $mail->msgHTML("$Message");
$mail->Body = $Message;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Thank you for sending your message.";
}

Related

How to create HTML form in which after user inputs email and clicks submit an email is sent to them from my gmail account?

I have an HTML form such as
<form name="contact-form" method="POST" action="sendemail.php">
<label>Name</label>
<input type="text" name="name" required="required">
<label>Email</label>
<input type="email" name="email" required="required">
<button type="submit" name="submit" required="required">Submit</button>
</form>
Now I want this such that when a user of my website enters their name and their email address and clicks submit a pdf is emailed to them on that email address from my Gmail. How would I go about writing sendemail.php for it?
Tried max's answer:
<?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'sample1#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for
//From email address and name
$mail->From = "sample1#gmail.com";
$mail->FromName = "Josh Bealer";
//To address
$mail->addAddress("receiveremail#gmail.com");
//CC and BCC
$mail->addCC("cc#example.com");
$mail->addBCC("bcc#example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Blah</i>";
$mail->AltBody = "This is the plain text version of the email content";
$mail->send();
?>
You can be cool and write a method using this https://www.php.net/manual/en/ref.imap.php
of you use the classic PHPmailer : https://github.com/PHPMailer/PHPMailer
on a debianoid you could try this:
apt install libphp-phpmailer
it will install you the PHPmailer class from ( https://github.com/PHPMailer/PHPMailer )
then you can follow the example from https://github.com/PHPMailer/PHPMailer#a-simple-example
I think it makes no sense that I copy the code from there for you ...
I made a super simple version
//PHPMailer Object
$mail = new PHPMailer;
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'josh#gmail.com'; // your SMTP username
$mail->Password = 'your_gmail_password'; // your SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for
//From email address and name
$mail->From = "josh#gmail.com";
$mail->FromName = "Josh Bealer";
//To address
$mail->addAddress("recepient#example.com");
//CC and BCC
$mail->addCC("cc#example.com");
$mail->addBCC("bcc#example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
try {
$mail->send();
}
catch (Exception $e) {
echo $e->getMessage();
}
catch (InvalidArgumentException $e) {
echo $e->getMessage();
}

how to get input email and send in php

I want to get an email address as input by the user and send an email to them using PHPMailer.
** My HTML code and PHP code**
<html>
<body>
<form method="post" action="Emails.php">
Email address <input type="email" name="emailaddress" id="emailaddress" required=""><br>
<input type="submit">
</form>
</body>
</html>
Emails.php
$_POST["emailaddress"] = "";
$emailaddress = ($_POST["emailaddress"]);
require 'C:\xampp\composer\vendor\autoload.php';
use PHPMailer\ PHPMailer\ PHPMailer;
use PHPMailer\ PHPMailer\ Exception;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'my email address'; // SMTP username
$mail->Password = 'my passsword'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail-> Port = 587;
$mail->setFrom('my email address', 'Mailer');
$mail->addAddress('$emailaddress', 'Dear User'); // Add a recipient
$mail->isHTML(true);
$mail->Subject = 'This is your password';
$mail->Body = 'Enter this as your password';
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: '.$mail - > ErrorInfo;
} else {
echo 'Message has been sent';
}
So I use this HTML and PHP code and get an error as
Invalid address: (to): $emailaddress The message could not be sent. Mailer Error: You must provide at least one recipient email address
My PHP version is 5.512. So could you please help me to solve this problem.

PHPMailer Error: Fatal error: Uncaught Error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::isSTMP()

I am trying to send Mails using PHPMailer But its Showing me Error. This is test code. and When it's done I am thinking to add it to my main code. but I don't know What's Wrong with this code. its just giving me this Error.
This is the Error:
Fatal error: Uncaught Error: Call to undefined method
PHPMailer\PHPMailer\PHPMailer::isSTMP() in
And Here is my Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
require "vendor/autoload.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$developmentMode = true;
$mailer = new PHPMailer($developmentMode);
try {
$mailer->SMTPDebug = 2;
$mailer->isSMTP(); //edited here
if ($developmentMode) {
$mailer->SMTPOptions = [
'ssl'=> [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
}
$mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->Username = "mygmail#gmail.com";
$mailer->Password = "password";
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer-> setFrom("mygmail#gmail.com", "Izaya");
$mailer->addAddress("anothergmail#gmail.com","orihara");
$mailer->isHTML(true);
$mailer->Subject = "Hey There";
$mailer->Body = "NICE TO MEET YOU IZAYA ";
$mailer->send();
$mailer->ClearAllRecipients();
echo "Mail has been Sent";
}catch (Exception $e) {
echo "Email Error.INFO:" . $mailer->ErrorInfo;
}
?>
</body>
</html>
You just made a mistake in typing.Here is the error you are getting $mailer->isSTMP();
Change it to $mailer->isSMTP();
Use this code below with version more than v6.0
// 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';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
// Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

send mail using php on form submit in htmo method post [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am newbie and i'm trying to send mail using php but unable to send mail when i click on submit button new window open which contain some part of my php code......i want to send email from user email id to my email id with the content of form
This is the first time i'm using php and i stuck in this
<?php
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
require 'class.smtp.php';
// require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "example";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = "example#gmail.com";
$mail->FromName = "ADMIN";
$mail->addAddress("example#gmail.com", "User 1");
$mail->IsHTML(true);
$mail->Subject = "form Submission";
$subject = $_POST['subject'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$name = $_POST['name'];
$company = $_POST['company'];
$city = $_POST['city'];
$message = $_POST['message'];
$mail->Body = "
<html>
<h2><br>Name: $name</br>
<br> Email: $email</br>
<br> Phone: $phone</br>
<br> Subject: $subject</br>
<br> Company: $company</br>
<br> City: $city</br>
<br> Message: $message </br></h2>
</html>";
$mail->AltBody = '';
if (! $mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
html--> action="http://myIPhere:7070/projectname/sendemail.php"
please help me to resolve this problem
i'm using tomcat server 9.0
my entire php code got print i think php code is not executing
in my webcontent i added
class.smtp.php
class.phpmailer.php
class.PHPMailerAutoload.php
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "test#gmail.com";
$mail->Password = "test#12#";
$mail->AddReplyTo("test#gmail.com", "test mail");
$mail->AddAddress('test#gmail.com', 'test mail ');
$mail->Body = "message:hiii";
if ($mail->send())
//if (mail($subject,$message, $headers))
{
echo "Thank you for sending mail us!";
} else {
echo "Mailed Error: " . $mail->ErrorInfo;
}
?>
this is the sample code..you can download smtp library function from github....
<?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;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers (smtp.gmail.com if you can use Gmail Account)
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#gmail.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
Use this configuration and download PHPMailer from GitHub.
https://github.com/PHPMailer/PHPMailer

Phpmailer giving SMTP ERROR

I have this error message. Could you please help me ?
My email.php;
<?php
header('Content-Type: text/html; charset=utf-8');
require 'PHPMailerAutoload.php';
$phpmailer = new PHPMailer;
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.coffeewritingcontent.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'iletisim#coffeewritingcontent.com';
$phpmailer->Password = 'mypassword';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Port = '587';
$phpmailer->From = 'iletisim#coffeewritingcontent.com';
$phpmailer->FromName = $_POST['name'];
$phpmailer->AddReplyTo($_POST['email'], $_POST['name']);
$phpmailer->addAddress('iletisim#coffeewritingcontent.com', 'İletişim Formu');
$phpmailer->isHTML(true);
$phpmailer->Subject = 'İletisim formu mesajı';
$phpmailer->Body = "isim: " . $_POST['name'] . "\r\n\r\nMesaj: " . stripslashes($_POST['message']);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->SMTPDebug = 4;
if(!$phpmailer->send()) {
echo 'Mail gonderilemedi. Hata: ' . $phpmailer->ErrorInfo;
exit;
}
echo 'Mail gonderildi.';
?>
my error;
2016-03-26 21:52:59 Connection: opening to
mail.coffeewritingcontent.com:587, timeout=10, options=array ( )
2016-03-26 21:53:09 SMTP ERROR: Failed to connect to server:
Connection timed out (110) Mail gonderilemedi. Error: Language string
failed to load: connect_host
Plase try this code. I'm using now in a server with GoDaddy and everything going good. Please make sure to require the php library with a require_once instance
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail#mydomain.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('mymail#mydomain.com', 'Name');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->setLanguage('es');
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Welcome!';
$mail->Body = 'This is a messagge test!';
if ( !$mail->send() ) :
echo 'Error while sending mail.';
else :
echo 'The messagge send correctly';
endif;
Did you create an instant of $phpmailer before do all those code? Probably you have to do it. So, if you already do that, please review your file PHPMailerAutoload.php and make sure that you have into your folder all and complety files that phpmailer provide us after the download content. I will show you an example for a correctly code that sends email from phpmailer.
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Please make sure too that you are sending emails from a server already upload. If you are using virtual serves like XAMPP, review this page for enable the smtp configuration: How to configure XAMPP to send mail from localhost?
Greetings.

Categories