Trying to implement a phpmailer into my project - php

I am new to php but I would like to use a phpmailer in my project. I have followed the steps from here: https://github.com/PHPMailer/PHPMailer but the form somehow does not send and I get a 404 problem. Can anyone help me understand what it is that I am doing wrong here?
My html file:
<div class="container">
<form method="POST" action="form.php">
<div class="section7">
<div>
<input type="text" name="company" placeholder="Firma*" required><br>
<input type="text" name="surname" placeholder="Nazwisko*" required><br>
<input type="email" name="email" placeholder="E-mail*" required><br>
<textarea name="message" placeholder="Wiadomość*" required></textarea>
</div>
<div>
<input type="text" name="address_code" placeholder="Kod pocztowy*" required><br>
<input type="text" name="name" placeholder="Imię*" required><br>
<input type="tel" name="phone" placeholder="Nr telefonu*" required>
</div>
</div>
<div class="checkbox">
<label for="policy"></label><input type="checkbox" id="policy" name="policy" value="policy" required>
</label>Wyrażam zgodę na przetwarzanie moich danych osobowych zgodnie z ustawą z dnia 29.08.1997 (Dz.U.nr 133,poz.883) o ich ochronie.</label><br>
</div>
<div class="btn-submit">
<input type="submit" value="Wyślij">
</div>
</form>
</div>
My php form file:
<?php
require_once('mailer/class.phpmailer.php');
require_once('mailer/class.smtp.php');
require_once('mailer/PHPMailerAutoload.php');
require_once('phpmaileroauthgoogle.php');
header('Content-Type: application/json');
$mail = new PHPMailer(true);
try {
$name = $_POST['name'];
$surname = $_POST['surname'];
$company = $_POST['company'];
$email = $_POST['email'];
$tel = $_POST['phone'];
$address = $_POST['address_code'];
$messageText = $_POST['message'];
if (empty($name) || empty($email) || empty($tel) || empty($messageText) || empty($surname) || empty($company) || empty($address)) {
http_response_code(400);
echo json_encode("All fields are required.");
exit;
}
$messageText .= "\nNumer telefonu: " . $tel;
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->FromName = "$name";
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->SMTPAutoTLS = false;
$mail->Username = "myemail";
$mail->Password = "mypassword";
$mail->SetFrom("myemail");
$mail->Subject = "Message sent from xxx website";
$mail->Body = $messageText;
$mail->AddAddress("myemail");
$mail->AddReplyTo($email);
if ($mail->send()) {
echo json_encode("Thank you the message has been sent.");
} else {
http_response_code(400);
echo json_encode("Sorry, there was an error");
}
} catch (\Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>

Related

How to get reCaptcha to work with ajax .load

I am looking to use reCaptcha with the jquery '.load' ajax function so that the information is passed across to my PHP contact form. I have established how to send across things such as name value, subject value etc with this method, however, I am unsure how to pass across the reCaptcha info.
As it currently stands when I submit the form I receive a PHP error advising 'Undefined index: g-recaptcha-response'. I believe this is to do with the Ajax side of things.
Any help on this would be amazing as I am at a total loss!
jQuery:
$("#contactForm").submit(function(event) {
event.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var phone = $("#phone").val();
var company = $("#company").val();
var message = $("#message").val();
var submit = $("#submit").val();
$(".form-message").load("contactForm.php", {
name: name,
email: email,
subject: subject,
phone: phone,
company: company,
message: message,
submit: submit
});
PHP:
if(isset($_POST['submit'])) {
require 'dist/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$message = $_POST['message'];
$secretKey = "--KEY--";
$responseKey = $_POST['g-recaptcha-response'];
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$response = file_get_contents($url);
$mail->HOST = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '--username--';
$mail->Password = '--password--';
$mail->setFrom('--email--', 'Contact Form Submission');
$mail->addAddress('--email--');
$mail->addReplyTo($email, $name);
$mail->isHTML(true);
$mail->Subject= $subject;
$mail->Body='<p>Name: '.$name. '<br>Email: '.$email.'<br>Subject: '.$subject.'<br>Phone: '.$phone.'<br>Company: '.$company.'<br>Message: '.$message.'</p>';
HTML:
<form method="POST" action="contactForm.php" id="contactForm">
<div class="form-group">
<input
type="text"
id="name"
name="name"
class="form-control"
placeholder="Full Name"
/>
</div>
<div class="form-group">
<input
type="text"
id="email"
name="email"
class="form-control"
placeholder="Email Address"
/>
</div>
<div class="form-group">
<input
type="text"
id="subject"
name="subject"
class="form-control"
placeholder="Subject"
/>
</div>
<div class="form-group">
<input
id="phone"
type="text"
name="phone"
class="form-control"
placeholder="Phone (optional)"
/>
</div>
<div class="form-group">
<input
id="company"
type="text"
name="company"
class="form-control"
placeholder="Company (optional)"
/>
</div>
<div class="form-group">
<textarea
class="form-control"
id="message"
name="message"
placeholder="Message"
style="height: auto"
rows="5"
></textarea>
</div>
<div
class="g-recaptcha"
data-sitekey="--KEY--"
></div>
<input
id="submit"
type="submit"
value="Submit"
class="btn btn-outline-primary btn-block mb-3"
name="submit"
/>
</form>
You can use the grecaptcha.getResponse() method to get the value of the captcha from the client side, then send that value with your ajax/jquery
<script type="text/javascript">
("#contactForm").submit(function(event) {
event.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var phone = $("#phone").val();
var company = $("#company").val();
var message = $("#message").val();
var submit = $("#submit").val();
var captcha = grecaptcha.getResponse(); //get captcha
$(".form-message").load("contactForm.php", {
name: name,
email: email,
subject: subject,
phone: phone,
company: company,
message: message,
submit: submit,
captcha : captcha
});
</script>
Then your php
<?php
if(isset($_POST['submit'])) {
require 'dist/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$message = $_POST['message'];
$secretKey = "--KEY--";
$responseKey = $_POST['captcha']; //captcha
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$response = file_get_contents($url);
$mail->HOST = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '--username--';
$mail->Password = '--password--';
$mail->setFrom('--email--', 'Contact Form Submission');
$mail->addAddress('--email--');
$mail->addReplyTo($email, $name);
$mail->isHTML(true);
$mail->Subject= $subject;
$mail->Body='<p>Name: '.$name. '<br>Email: '.$email.'<br>Subject: '.$subject.'<br>Phone: '.$phone.'<br>Company: '.$company.'<br>Message: '.$message.'</p>';

Error in PHP Mailer while executing in localhost

As I am beginner in using PHPmailer trying to send mail in localhost (XAMPP) server. I included class.phpmailer.php and class.smtp.php file but I'm getting an error message "there is an error" To resolve this I changed gmail account IMAP settings as Enable and and allow less secure apps.
But the problem has been not resolved. I get:
Warning:fwrite() expects parameter 1 to be resource, integer given in C:\xampp\htdocs\email-phpmailer\class\class.smtp.php on line 1023
Code I have Tried
<?php
//index.php
$error = '';
$name = '';
$email = '';
$subject = '';
$message = '';
function clean_text($string)
{
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
return $string;
}
if(isset($_POST["submit"]))
{
if(empty($_POST["name"]))
{
$error .= '<p><label class="text-danger">Please Enter your Name</label></p>';
}
else
{
$name = clean_text($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name))
{
$error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
}
}
if(empty($_POST["email"]))
{
$error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
}
else
{
$email = clean_text($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$error .= '<p><label class="text-danger">Invalid email format</label></p>';
}
}
if(empty($_POST["subject"]))
{
$error .= '<p><label class="text-danger">Subject is required</label></p>';
}
else
{
$subject = clean_text($_POST["subject"]);
}
if(empty($_POST["message"]))
{
$error .= '<p><label class="text-danger">Message is required</label></p>';
}
else
{
$message = clean_text($_POST["message"]);
}
if($error == '')
{
require 'class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = 'smtp.gmail.com'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '587'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = 'abc#gmail.com'; //Sets SMTP username
$mail->Password = 'MyPass'; //Sets SMTP password
$mail->SMTPSecure = 'ssl'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = $_POST["email"]; //Sets the From email address for the message
$mail->FromName = $_POST["name"]; //Sets the From name of the message
$mail->AddAddress('xyz#gmail.com', 'its me'); //Adds a "To" address
//$mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = $_POST["subject"]; //Sets the Subject of the message
$mail->Body = $_POST["message"]; //An HTML or plain text message body
if($mail->Send()) //Send an Email. Return true on success or false on error
{
$error = '<label class="text-success">Thank you for contacting us</label>';
}
else
{
$error = '<label class="text-danger">There is an Error</label>';
}
$name = '';
$email = '';
$subject = '';
$message = '';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Send an Email on Form Submission using PHP with PHPMailer</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container">
<div class="row">
<div class="col-md-8" style="margin:0 auto; float:none;">
<h3 align="center">Send an Email on Form Submission using PHP with PHPMailer</h3>
<br />
<?php echo $error; ?>
<form method="post">
<div class="form-group">
<label>Enter Name</label>
<input type="text" name="name" placeholder="Enter Name" class="form-control" value="<?php echo $name; ?>" />
</div>
<div class="form-group">
<label>Enter Email</label>
<input type="text" name="email" class="form-control" placeholder="Enter Email" value="<?php echo $email; ?>" />
</div>
<div class="form-group">
<label>Enter Subject</label>
<input type="text" name="subject" class="form-control" placeholder="Enter Subject" value="<?php echo $subject; ?>" />
</div>
<div class="form-group">
<label>Enter Message</label>
<textarea name="message" class="form-control" placeholder="Enter Message"><?php echo $message; ?></textarea>
</div>
<div class="form-group" align="center">
<input type="submit" name="submit" value="Submit" class="btn btn-info" />
</div>
</form>
</div>
</div>
</div>
</body>
</html>

PHP script with form not sending the email

I am having some problems with php. Well, the code, when uploaded to the server and run in browser is working and the email is arriving, using this code below:
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->IsSMTP();
//$mail->IsSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
$mail->Username = "exemple#gmail.com";
$mail->Password = "password";
$name = "catarina";
$email = "myEmail#hotmail.com";
$message = "test";
$mail->setFrom($email, $name);
$mail->addAddress('me#exemple.io');
$mail->Subject = 'Contact Site';
$mail->Body = $message;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
The problem is, when I change this code a little to send with a form, the email never arrives:
js:
function submitForm() {
$.ajax({type:'POST', url:'email-action.php', data:$('#contact-form').serialize(), success: function(result){
$('.submit').html('send');
$('.send').removeClass('no-show');
$('.send').removeClass('no-show-mobile');
}});
};
html:
<form action="/" onsubmit="return submitForm();" method="post" name="contactform" class="contact-form wow zoomIn" data-wow-delay="0.6s" id="contact-form">
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
<input placeholder="Name" class="input-field" name="name" required="" type="text">
</div>
<div class="col-md-12">
<input placeholder="E-mail" class="input-field" name="email" required="" type="email">
</div>
</div>
</div>
<div class="col-md-6">
<textarea placeholder="Message" class="input-field" name="message"></textarea>
<input value="Send Message" class="input-send submit" type="submit" name="submit">
</div>
<div class="col-md-12 send no-show hidden-xs"><button class=" botao btn btn-sucess"><h4 class="">Message sent sucessfully! We will get in touch shortly.</h4></button></div>
<div class="col-md-12 send no-show-mobile visible-xs"><button class=" botao btn btn-sucess"><h4 class="">Message sent sucessfully!</h4></button></div>
</form>
php:
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->IsSMTP();
//$mail->IsSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
$mail->Username = "exemple#gmail.com";
$mail->Password = "password";
///this is the thing that change for one script to another
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
/////
$mail->setFrom($email, $name);
$mail->addAddress('me#exemple.io');
$mail->Subject = 'Contact Site';
$mail->Body = $message;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Jquery Ajax, PHPMailer doesn't send emails even if there's no error but works if i use stand alone page with fix values

I have this simple bootstrap form that i run on my localhost, it accepts name email and message and a custom captcha in a form of a math question; On submit i used jquery ajax to fetch the data to emailme.php that contains the phpmailer code.. My problem is, no email was sent even if there's no error and the network status is 200 and i can also see this:
http://localhost/emailme.php?name=myname&email=myemail#gmail.com&message=test
however it works if i just use the phpmailer stand alone code with fixed values. how can i make it work?
HTML:
<form id="emailme" method="post">
<div class="form-group">
<input type="text" class="form-control" name="name" id="name" placeholder="e.g. John Doe">
<span id="err_name" class="text-danger"></span>
</div>
<div class="form-group">
<input type="text" class="form-control" name="email" id="email" placeholder="e.g. example#domain.com">
<span id="err_email" class="text-danger"></span>
</div>
<div class="form-group">
<textarea name="message" id="message" cols="30" rows="10" class="form-control" placeholder="Your message"></textarea>
<span id="err_message" class="text-danger"></span>
</div>
<div class="form-group">
<label for="human">5 + 2 = ?</label>
<input type="text" id="human" name="human" class="form-control" placeholder="Your Answer">
<span id="err_human" class="text-danger"></span>
</div>
<input type="submit" class="btn btn-primary btn-sm" value="Send">
</form>
JQUERY:
$("#emailme").on('submit',function(e){
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var message = $("#message").val();
var human = $("#human").val();
var emailRegex = /(.+)#(.+)\.(com|edu|org|etc)$/g;
if(name!==''&&email!==''&&message!==''&&human!==''){
if(email.match(emailRegex)){
if(human==7){
$.ajax({
url:'emailme.php',
typ:'post',
data:{name:name,email:email,message:message},
success:function(response){
console.log(response);
$("#mail-status").html(response);
$("#emailme")[0].reset();
},
error:function(XMLHttpRequest,textStatus,errorThrown){
console.log(textStatus+errorThrown);
}
});
}
else{
$("#mail-status").html("unable to submit form, you're not human");
}
}
else{
$("#err_email").append("Invalid email format");
}
}
else if(name==''){
$("#err_name").append("Name cannot be empty");
}
else if(email==''){
$("#err_email").append("Email cannot be empty");
}
else if(message==''){
$("#err_message").append("Message cannot be empty");
}
else if(human==''){
$("#err_human").append("Please answer the security question");
}
});
PHP:
<?php
date_default_timezone_set('Etc/UTC');
require 'phpmailer/PHPMailerAutoload.php';
// Set the email address submissions will be sent to
$email_address = 'myemail#gmail.com';
// Set the subject line for email messages
$subject = 'Test email from localhost using PHPMailer';
// Check for form submission
if(isset($_POST['name'], $_POST['email'], $_POST['message'])){
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypassword";
$mail->setFrom($_POST['email'], $_POST['name']);
$mail->addAddress($email_address, 'myname');
$mail->Subject = $subject;
$mail->Body = 'From:'.$_POST['name'].'(' . $_POST['email'] . ')'.'<p><b>Message</b><br/>' . $_POST['message'] . '</p>';
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
?>

Mail send function not getting called from .php Customer Form

I am new to PHP coding. I have created a Customer form, followed by send e-mail function. When a Customer submits data (including E-Mail and password) he should receive a confirmation e-mail with User ID (same as entered E-Mail Id) and entered Password.
At this moment, with my current code, when a Customer submits the form, database gets updated, but no e-mail is send to the user. Can anyone point out what needs to be changed to ensure that send e-mail function works correctly.
<!DOCTYPE html>
<html>
<head>
<title>Registration Desk</title>
</head>
<body>
<div class="form">
<form id="contactform" action="reg_submit.php" method="post">
<p class="contact"><label for="name">Name</label></p>
<input id="name" name="name" placeholder="First and last name" required="" tabindex="1" type="text">
<p class="contact"><label for="add">Address</label></p>
<textarea id="add" name="add" style="width:85%; height:60%; margin-top:1%" required=""></textarea>
<fieldset>
<label>Birthday</label>
<input type="date" name="dob" value="yyyy-mm-dd" required="">
</fieldset>
<label>I am</label> <br><br>
<input type="radio" name="sex" value="male" >Male
<input type="radio" name="sex" value="female">Female
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" class="field" placeholder="Please enter a valid emailid" required="" type="email">
<p class="contact"><label for="password">Create a password</label></p>
<input type="password" id="password" name="password" required="">
<p class="contact"><label for="repassword">Confirm your password</label></p>
<input type="password" id="repassword" name="repassword" required="">
<br><br>
<p class="contact"><label for="phone">Mobile phone</label></p>
<input id="phone" name="phone" placeholder="phone number" required="" type="text"> <br>
<input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!" type="submit">
</form>
</div>
</div>
</body>
</html>
<?php
error_reporting( 0);
$connect=mysqli_connect("localhost","wbtecqoj_saltee","webuildtec1","wbtecqoj_salteegroup");
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if( $_POST["password"]!= $_POST["repassword"])
{
?>
<script type="text/javascript">
alert("password miss matched!!!.");
history.back();
</script>
<?php
}
if($_POST["name"] && $_POST["add"] && $_POST["phone"] && $_POST["email"] && $_POST["password"] && $_POST["dob"] )
{
$insert="INSERT INTO `db`.`new_user` (`id`, `name`, `add`, `contact`, `email`, `pass`, `dob`, `gender`,`code`) VALUES (NULL, '$_POST[name]', '$_POST[add]', '$_POST[phone]', '$_POST[email]', '$_POST[password]', '$_POST[dob]', '$_POST[sex]', 'SAL1000000')";
if(!mysqli_query($connect,$insert))
{
echo die('Error: ' . mysqli_error($connect));
}
else
{
$to=$_POST['email'];
$from= "admin#wbtec.in";
$subject="Welcome to xyz Group";
$message="Welcome " . $_POST['name'] . "Dear Customer,
Your Card Number is " .$Ccode.$cookieId. " User id -" . $_POST['email'] . "Your Password -" . $_POST['password'].
"Thanking You,
Customer Care,";
$header = "From" .$from;
if(isset($_POST['btnSend']))
{
$res = mail($to,$subject,$message,$header);
if($res)
{
echo 'Message send';
}
else
{
echo 'msg not send';
}
}
}}
mysqli_close($connect);
?>
Remove the
if(isset($_POST['btnSend']))
{
}
You are checking for
if(isset($_POST['btnSend']))
But your form doesn't contain an input named btnSend, you should be able to remove that if statement altogether
I suggest you to use PHPMailer from
http://sourceforge.net/projects/phpmailer/
With the PHPMailer class you can specify the outgoing SMTP server and authenticate with it properly. Here is an example how I used it:
<?php
require("class.phpmailer.php");
class Mailer
{
function send($email, $subject, $body, $attachment1)
{
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "mail.xyz.com"; // your SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "authname"; // SMTP username
$mail->Password = "authpassword"; // SMTP password
$mail->From = "info#xyz.com";
$mail->FromName = "info#xyz.com";
$mail->AddAddress($email);
$mail->WordWrap = 50; // set word wrap
if ($attachment1 != "") {
$mail->AddAttachment($attachment1); // attachment1
}
$mail->IsHTML(false); // send as HTML
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send())
{
return -1;
}
else
{
return 0;
}
}
}
?>
Hope that helps!
u have to download php mailer library which have to files
PHP mailer
class.phpmailer.php and other class.smtp.php then add this file at same directory which have php code which is shown below..
<?PHP
require_once('class.phpmailer.php');
if('POST' == $_SERVER['REQUEST_METHOD']) {
// process the form here
$subject = "This is subject testing1";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true); // send as HTML
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
//$mail->Username = "gmailusername"; // GMAIL username
//$mail->Password = "password"; // GMAIL password
$mail->From = 'email id';
$mail->FromName = "FrontName";
$mail->Subject = $subject;
$mail->Body = "this is html body"; //HTML Body
$emailId='email id';
$emails = explode(",",$emailId);
foreach($emails as $email)
$mail->AddAddress($email);
if($mail->Send()){
echo "Message sent successfully";
}else{
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
?>
<form action="" method="post">
<input type="submit" name='button1'value="sent mail" />
</form>

Categories