I have php website when try to submit contact form Post method not working. All of form elements inside of index.html i'll share the codes with you. I'll be happy if you could help me
In HTML File (index.php)
<form id="main-contact-form" method="post" action="sendemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="İsim Soyisim" required>
</div>
<div class="form-group">
<input type="email" name="mail_adress" class="form-control" placeholder="Mail Adresi" required>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Konu" required>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="8" placeholder="Mesaj" required></textarea>
</div>
<button type="submit" name="send" class="btn btn-primary">Mesaj Gönder</button>
</form>
in PHP (sendemail.php)
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xx#xxxxx.com'; // SMTP username
$mail->Password = 'xxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('xxx#xxxxxx.com', 'xx xx xx'); //Set who the message is to be sent from
$mail->addAddress('xxx#xxxxx.com', 'xx xx xx xx'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = 'Mesaj Konusu'.$_POST['name'];
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
echo $_POST['subject'];
exit;
}
echo 'Message has been sent';
?>
Thank You
Try to compare with the === operador, to compare not only the same value, but also the same data type.
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// …
}
I found the answer ajax prevent to POST method when i fix that everthings are became good
var form = $('#main-contact1-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Mail Gönderiliyor...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">Mesajınız başarı ile iletilmiştir. En kısa sürede tarafınıza dönüş yapılacaktır.</p>').delay(3000).fadeOut();
});
});
when i delete this code everythings are good. How to fix that without delete it..? That's a new question to ask...
<?php
function sendmail($to,$subject,$message,$from)
{
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = "From: " . $from. "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
}
?>
you write ==POST(capital letters), and use method = post(small letters), so change it to small or capital in both places. or check sendmail.php
Related
I've been trying this for a long but failed till now.
I've tried changing form names, or attributes names but didn't work.
Here is the code for my form:
<form action="contact_process.php" class="office_contact_form" id="contactForm" method="post" name="contactForm" novalidate="">
<div class="form-group col-md-12">
<input class="form-control" id="name" name="name" placeholder="Name" type="text">
</div>
<div class="form-group col-md-12">
<input class="form-control" id="email" name="email" placeholder="Email Address *" type="text">
</div>
<div class="form-group col-md-12">
<input class="form-control" id="subject" name="subject" placeholder="Subject" type="text">
</div>
<div class="form-group col-md-12">
<textarea class="form-control" id="message" name="message" placeholder="Your Message" rows="1"></textarea>
</div>
<div class="form-group col-md-12">
<button class="btn p_btn" type="submit" value="submit">Send Message</button>
</div>
</form>
Here is my PHP code:
<?php
$to = "hello1224#gmail.com";
$from = $_REQUEST['yourname'];
$name = $_REQUEST['youremail'];
$headers = "From: $from";
$subject = "You have a message from your attornyeproducts.com";
$fields = array();
$fields{"yourname"} = "name";
$fields{"youremail"} = "email";
$fields{"subject"} = "subject";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $subject, $body, $headers);
?>
I'm trying to receive the data from the this contact form to the email's id.
Did you tried https://github.com/PHPMailer/PHPMailer ?
simple example: https://github.com/PHPMailer/PHPMailer
example to fit your case:
<?php
use PHPMailer\PHPMailer\PHPMailer;
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 = 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("YOUREMAIL#gmail.com");
$mail->addAddress("hello1224#gmail.com"); // Add a recipient
$fields = array(
"yourname" => $_REQUEST['yourname'],
"youremail" => $_REQUEST['youremail'],
"subject" => $subject ,
"phone" => "phone",
"message" => "message",
);
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject
$mail->Body = $body;
$mail->AltBody = $body;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
I did not test your fields. You can test your field to ensure they have correct values and then pass those values to this function.
I suggest you use FILTER_VALIDATE_EMAIL to ensure you have a valid email.
Also you can check that the post keys that you are expecting actually exist:
$message=(isset($_POST['message']))?$_POST['message']:'default message';
function send($subject,$msg,$email,$from,$replyto=null){
$replyto=(isset($replyto) && filter_var($replyto, FILTER_VALIDATE_EMAIL) )?$replyto:'contact#mydomain.com';
$params="-fcontact#mydomain.com";
$subject = $subject;
$message = "<div style='font-family: Arial, Helvetica, sans-serif;'>";
$message .= $msg;
$message .="</div>";
$headers = "From: =?utf-8?b?".base64_encode($from)."?= <contact#mydomain.com>\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= 'Bcc: info#mydomain.com' . "\r\n";
$headers .= 'Reply-To: '.$replyto . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$to = $email;
if(isset($_SERVER['REMOTE_ADDR']) && in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ))) return true;
return mail($email, $subject, $message, $headers,$params);
}
This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 6 years ago.
I'm a little bit new with with php and i just want to ask how can i make the the "Send Message" button send the inputted information on the form i created to my email.
Here's the code:
<section id="three">
<h2>Email Me!</h2>
<p>You will receive a reply within 24-48 hours.</p>
<div class="row">
<div class="8u 12u$(small)">
<form method="post" action="MAILTO:sample#email.com">
<div class="row uniform 50%">
<div class="6u 12u$(xsmall)"><input type="text" name="name" id="name" placeholder="Name" /></div>
<div class="6u$ 12u$(xsmall)"><input type="email" name="email" id="email" placeholder="Email" /></div>
<div class="12u$"><textarea name="message" id="message" placeholder="Message" rows="4"></textarea></div>
</div>
</form>
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
<div class="4u$ 12u$(small)">
<ul class="labeled-icons">
<li>
<h3 class="icon fa-home"><span class="label">Address</span></h3>
1234 Somewhere Rd.<br />
Nashville, TN 00000<br />
United States
</li>
<li>
<h3 class="icon fa-mobile"><span class="label">Phone</span></h3>
000-000-0000
</li>
<li>
<h3 class="icon fa-envelope-o"><span class="label">Email</span></h3>
hello#untitled.tld
</li>
</ul>
</div>
</div>
</section>
Thanks!
I'm not quite sure but email from php server almost all of them ends up in spam folder (trust issues by mail provider). But if you're interested, you can send mail via email function:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
source: PHPDocs
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
What I recomend using is Mail sending servive like SendGdrid or MailChimp, those are easy to use and have pretty simpe API to work with. Free plan has a lot to offer, And you can send plain html through their api and it will be fine.
<?php
if(isset($_POST['submit'])) // on submit click no need to action of the form
{
$name = $_POST['name'];
$email = $_POST['email'];
$to = "somebody#example.com";
$subject = "My subject";
$body = "name:" . $name . "Email:" . $email;
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$body,$headers);
}
?>
I would recommend using PHPMailer to send email from PHP. Here's the steps to accomplish this.
Go to the Github repository.
Download the ZIP.
Extract it in your public_html directory.
include '/path/to/PHPMailer/PHPMailerAutoload.php'; at the top of your PHP script.
Get the values from the HTML form like you normally would.
Here's an example...
index.html
<form action="index.php" method="post">
<input type="email" name="email">
<input type="text" name="name">
<input type="text" name="subject">
<input type="text" name="message">
</form>
index.php
include '/path/to/PHPMailer/PHPMailerAutoload.php';
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$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 = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, "ssl" also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('your email', 'your name'); // from
$mail->addAddress($email, $name); // to
$mail->isHTML(true); // if html
$mail->Subject = $subject;
$mail->Body = $message; //HTML
if($mail->send()){
echo 'Mail sent!';
}
else {
echo 'Mail failed!';
}
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
This is my php code to send email. I got the massage 'Message was sent, you can send another one' But email is not sending.
<h4>Please fill out the following form and we will be in touch with you soon.</h4>
<form action="mytest.php" method="post" id="contactform">
<ol>
<li>
<label for="name">Your Name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="message">Message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
<div class="clr"></div>
</li>
</ol>
</form>
<?php
if(!$_POST) exit;
$email = $_POST['email'];
$errors=0;
if($errors==1) echo $error;
else{
$email_from = $_POST['email'];
$email_from = "from#gmail.com";
$headers = "From: " . strip_tags( $_POST['name'] ) . "\r\n";
$mail_to_send_to = "to#gmail.com";
$your_feedbackmail = "from#gmail.com";
$sendflag = 'send';
if ( $sendflag == "send" )
{
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $your_feedbackmail" . "\r\n" . "Reply-To: $email" . "\r\n" ;
$a = mail( $mail_to_send_to, "Feedback Form Results", $message, $headers );
if ($a)
{
print("Message was sent, you can send another one");
} else {
print("Message wasn't sent, please check that you have changed emails in the bottom");
}
}
}
?>
I'm Using Cpanel to host my web site. Is there any special configurations to do this? I'm new to php. Please help me.
mail function doesn't provide authentication functionality. Your have to use Mail class from Mail Pear package. See here for an example:
example
I am assuming you are on shared hosting based on the fact that you are using Cpanel, some shared hosting solutions don't play nicely with php's mail() function, I have found that using phpmailer https://github.com/PHPMailer/PHPMailer works better and provides more functionality
to use phpmailer :
download from the link, place the files in your a folder accessible to your web application.
code :
$email_from = $_POST['email'];
$email_from = "from#gmail.com"; // this overwrites the $_POST['email'] value, check this
$email_from_name = "Nishanthi";
$gmailUsername = "from#gmail.com";
$gmailPassword = "mysecretpassword";
$mail_to_send_to = "to#gmail.com";
$your_feedbackmail = "from#gmail.com";
$emailSubject = "Place Subject Here";
$emailContent = "This message can contain <b>HTML</b>";
require '[path_to_your_phpmailer_files]/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2; //Enable SMTP debugging
$mail->Debugoutput = 'html'; //Ask for HTML-friendly debug output
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $gmailUsername; // SMTP username
$mail->Password = $gmailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($email_from, $email_from_name);
$mail->addAddress($mail_to_send_to);
$mail->addReplyTo($your_feedbackmail);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $emailSubject;
$mail->Body = $emailContent;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message was sent, you can send another one';
}
?>
I've tried out a few PHP contact form tutorials but none seem to work for me. I'm not sure what I'm doing wrong. I tested it in localhost and nothing, so I went ahead and hosted it to see if that would work but still nothing.
HTML
<form class="form" action="form_process.php" method="post" name="contact_form">
<p class="name">
<label for="name">Name</label><br>
<input type="text" name="name_first" id="name" placeholder="First" />
<input type="text" name="name_second" id="name" placeholder="Last" />
</p>
<p class="email">
<label for="email">Email</label><br>
<input type="text" name="email" id="email" placeholder="mail#example.com" />
</p>
<p class="text">
<label for="email">Comments</label><br>
<textarea name="text" placeholder="Write something to us" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
form_process.php
<?php
$name_first = $_POST['name_first'];
$name_second = $_POST['name_second'];
$email = $_POST['email'];
$text = $_POST['text'];
$from = 'From: ';
$to = 'EMAIL HERE';
$subject = 'Hello';
$body = "From: $name_first\n $name_second\n E-Mail: $email\n Message:\n $text";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
header("Location: index.html");
echo '<p>Your message has been sent!</p>';
exit;
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
Your error is from the line
if ($_POST['submit']) {
This is because you did not give your submit button a name of submit. If you fix this line in your HTML it should fix the issue:
<input type="submit" name="submit" value="Send" />
I recommend that you set an error log in your php.ini file. That way you can see the error for yourself which would have said something similar to:
PHP Notice: Undefined index: submit in
/var/www/pwd/blah/form_process.php on line 12
If you are working in localhost mode you will need phpmailer.
First you need download phpmailer from here https://github.com/PHPMailer/PHPMailer/archive/master.zip
Then paste in your folder. If my coding doesn't clear you, you can check from
https://github.com/PHPMailer/PHPMailer
<?php
require 'PHPMailerAutoload.php'; // Your Path
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // 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'; // Your mail
$mail->Password = 'secret'; // Your mail password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->From = 'from#example.com';
$mail->FromName = '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');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
//Check Condition
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Second way.
If you working testing in online mode(Have own domain and hosting), you can just randomly copy and paste.
Doesnt required phpmailer.
if(isset($_POST['email'])) $email = $_POST['email'];
else $email = "";
function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$myname."\" <".$myemail.">\r\n";
return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers));
}
if(isset($Submit) && $Submit=="Go") {
$emailContent ='';
$sent=send_mail($name, "yourmailname.gmail.com", "Fido", $receipientEmail, "Testing", $emailContent);
if($sent) {
echo $emailContent;
header('Location: contact.php');
}else{
echo "Failed";
exit;
}
}
?>
Regards
I am seriously struggling and have tried so many different methods to get my form to attach a file to the email sent through PHP.
This is the HTML form:
<form id="form1" enctype="multipart/form-data" action="submit/applicationscript.php" method="post" name="form1">
<input checked type="radio" name="school" value="English Martyres"/>
<input type="radio" name="stop" value="stop1" />
<input type="radio" name="stop" value="stop2" />
<input type="radio" name="stop" value="stop3" />
<input type="radio" name="stop" value="stop4" />
<input type="checkbox" name="mon" value="Monday" />
<input type="checkbox" name="tue" value="Tuesday" />
<input type="checkbox" name="wed" value="Wednesday" />
<input type="checkbox" name="thu" value="Thursday" />
<input type="checkbox" name="fri" value="Friday" />
<input type="text" class="text" name="name" required placeholder="First Name" /></div>
<input type="text" class="text" name="surname" required placeholder="Surname" /></div>
<input type="text" class="text" name="dob" required maxlength="10" placeholder="Date of Birth" />
<input type="file" name='uploaded_file' required />
<input type="submit" id="form1" name="submit" value="Submit" onClick="document.form1.submit()">
</form>
This is the PHP:
<?php
// Read POST request params into global vars
$to = $_POST['my#email.com'];
$from = $_POST['from#email.co.uk'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$ok = #mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
It either sends and does not attach an attachment or it is unable to send or the $message is empty and therefore does not send.
Cannot anyone please help me, really need this to work and don't have a great knowledge of PHP, have looked at so many articles but cannot get my head around it.
I use PHPMailer for this and I haven't had any issues.
Get it here: https://github.com/PHPMailer/PHPMailer
Here is an example:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$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 encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = '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');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}