How to send PHP email after posting data to Database - php

I am currently working on a quote form. After submitting the form, there was an email set to send submitted record back to client as copy. However, as I was using Mandrill for transaction emails, it's no longer free. I don't want to use any paid service and am now looking to send the same email using PHPMailer. I am finding it difficult to understand to call php to send email. Any help? I am open for options. All I want to send email after form submits.
email.js
function finalize_things(data, order_id){
//posting data to the server side page
$.post(window.location.origin+'/post/', data,function(response){
if(response == 'success'){
console.log(response);
send_email(order_id, data.email, data.firstname, data.project_details, data.file_names);
} else {
console.log(response);
alert('order not placed.');}
});
}
function send_email(order_id, email, firstname, project_details, file_names){
var html_message = "message here"
data = {
"key": "xxxxxxxxx",
"message": {
"html": html_message,
"text": "",
"subject": "Your subject",
"from_email": "test#test.com",
"from_name": "Company name",
"to": [{
"email": email,
"name": firstname
}
]},
"async": false
};
$.ajax({url: 'https://mandrillapp.com/api/1.0/messages/send.json',
type: 'POST',
data: data,
success: function(resp){
console.log(resp); }
});
PHPMAILER Code:
include_once '/../../PHPMailer/cms_db.php';
require_once '/../../PHPMailer/PHPMailerAutoload.php';
require_once '/../../PHPMailer/config.php';
if (isset($_POST["email"]) && !empty($_POST["email"])) {
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
$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("companyemail#xyz.com", "Company Name");
$mail->addAddress($email, $firstname); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$bodyContent = "test message";
$mail->Subject = "Your Quote ID";
$mail->Body = $bodyContent;
$mail->AltBody = $bodyContent;
if(!$mail->send()) {
echo "Message could not be sent.";
$error = '<div class="alert alert-danger"><strong>Mailer Error: '. $mail->ErrorInfo.'</strong></div>';
} else {
$error = '<div class="alert alert-success"><strong>Message has been sent</strong></div>';
}
}

So, if you don't want to use external services like gmail... You need to set up your own mail server (postfix, sendmail etc.) Please note, that webservers very often has potfix onboard (httpd + php + mysql + postfix) already.
Has your hosting postfix already? Check this by using standard mail function, php script like :
<?php
$to = 'yourmail#gmail.com';
$subject = 'test subj';
$mail_body = 'test body';
mail($to, $subject, $mail_body);
?>
If it works -- write your own script based on this code or use phpmailer (it has settings for local mail daemon)
PS PHPMailer can send mail via extenal webserver, like gmail https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps (key line here: $mail->isSMTP();) or via local server, such as postfix -- see example here -- key line is $mail->isSendmail();
and your current code snippet is for using EXTERNAL service, not for LOCAL!

Changes in your js this line:
$.ajax({url: 'https://mandrillapp.com/api/1.0/messages/send.json',
to:
$.ajax({url: 'http://yourserver.tld/send_phpmailer.php',
And use something like this in send_phpmailer.php:
<?php
////// Part 1. Set up variables
$key = $_POST['key']; // need for mandrill, you can omit this
$html = $_POST['message']['html'];
$text = $_POST['message']['text'];
$subject = $_POST['message']['subject'];
$from_email = $_POST['message']['from_email'];
$from_name = $_POST['message']['from_name'];
$to_email = $_POST['message']['to']['email'];
$to_name = $_POST['message']['to']['name'];
////// Part 2. Including PHPMailer
include_once '/../../PHPMailer/cms_db.php';
require_once '/../../PHPMailer/PHPMailerAutoload.php';
require_once '/../../PHPMailer/config.php';
////// Part 3. Sending letter by PHPMailer
$mail = new PHPMailer;
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username#gmail.com";
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom( $from_email, $from_name);
//Set an alternative reply-to address
//$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($to_email, $to_name);
//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($html);
//Replace the plain text body with one created manually
$mail->AltBody = $text;
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

<?php
include ('config.php');
if(isset($_POST['submit']))
{
$name=mysqli_real_escape_string($conn,$_POST['name']);
$email=mysqli_real_escape_string($conn,$_POST['email']);
$phone=mysqli_real_escape_string($conn,$_POST['phone']);
$msg=mysqli_real_escape_string($conn,$_POST['msg']);
$sql="insert into contact(`name`,`email`,`phone`,`msg`) values('$name','$email','$phone','$msg')";
// $result=mysqli_query($conn,$sql);
if(mysqli_query($conn, $sql)){
$to='akhilsai.innovkraft#gmail.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
$sentmail=swiftmail($to, $subject, $message, $headers);
header('localtion:index.html');
}
else{
echo "ERROR:";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Feedback Form</title>
</head>
<body>
<div class="main">
<div class="info">Give Your Feedback!</div>
<form action="#" method="post" name="form" class="form-box">
<label for="name">Name</label><br>
<input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
<label for="email">Email ID</label><br>
<input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
<label for="phone">Phone</label><br>
<input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
<label for="message">Message</label><br>
<textarea name="msg" class="msg-box" placeholder="Enter Your Message Here..." required></textarea><br>
<input type="submit" name="submit" value="Send" class="sub-btn">
</form>
</div>
</body>
</html>

i try this coding in my own way
<?php
include ('config.php');
if(isset($_POST['submit']))
{
$name=mysqli_real_escape_string($conn,$_POST['name']);
$email=mysqli_real_escape_string($conn,$_POST['email']);
$phone=mysqli_real_escape_string($conn,$_POST['phone']);
$msg=mysqli_real_escape_string($conn,$_POST['msg']);
$sql="insert into contact(`name`,`email`,`phone`,`msg`) values('$name','$email','$phone','$msg')";
// $result=mysqli_query($conn,$sql);
if(mysqli_query($conn, $sql)){
$to='akhilsai.innovkraft#gmail.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
$sentmail=swiftmail($to, $subject, $message, $headers);
header('localtion:index.html');
}
else{
echo "ERROR:";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Feedback Form</title>
</head>
<body>
<div class="main">
<div class="info">Give Your Feedback!</div>
<form action="#" method="post" name="form" class="form-box">
<label for="name">Name</label><br>
<input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
<label for="email">Email ID</label><br>
<input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
<label for="phone">Phone</label><br>
<input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
<label for="message">Message</label><br>
<textarea name="msg" class="msg-box" placeholder="Enter Your Message Here..." required></textarea><br>
<input type="submit" name="submit" value="Send" class="sub-btn">
</form>
</div>
</body>
</html>

Related

Why mail was sending without confirm the form or don't sending at all and get Timeout?

I have a very interesting problem with my script. I need to send a brief to my email, and I use PHP Mailer for that.
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.webtests.xyz';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'yapik#webtests.xyz';
$mail->Password = '1104Romik!';
$mail->setFrom('yapik#webtests.xyz', 'Yaroslav Kretov');
$mail->addAddress($_POST['email'], $_POST['name']);
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'PHPMailer contact form';
$mail->isHTML(false);
$mail->Body = <<<EOT
Email: {$_POST['email']}
Name: {$_POST['name']}
Message: {$_POST['message']}
EOT;
if (!$mail->send()) {
$msg = 'Sorry, something went wrong. Please try again later.';
} else {
$msg = 'Message sent! Thanks for contacting us.';
}
} else {
$msg = 'Share it with us!';
}
}
else{
echo 'error';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact form</title>
</head>
<body>
<h1>Do You Have Anything in Mind?</h1>
<?php if (!empty($msg)) {
echo "<h2>$msg</h2>";
} ?>
<form method="POST">
<label for="name">Name: <input type="text" name="name" id="name"></label><br><br>
<label for="email">Email: <input type="email" name="email" id="email"></label><br><br>
<label for="message">Message: <textarea name="message" id="message" rows="8" cols="20"></textarea></label><br><br>
<input type="submit" value="Send">
</form>
</body>
</html>
It sends a brief but before I confirm this form, or don't send it at all and give me timeout. I don't know what I should do.

PHPmailer fuction only will receive from one email

I have searched for this answer for the past few days and have tried everything to make this work so please help.
I had made a contact form but I will only receive an email if I use the email that the form is submitting to. If I use any other email it will still said the email is sent but when I check my inbox there is nothing there. Same as my junk and sent folders. Although if I complete the form with my email I will get an email in my inbox. (So the form email and the email address submitting to is the same).
This is my index.php
<!DOCTYPE html>
<html>
<head>
<title>Send an Email</title>
</head>
<body>
<center>
<h4 class="sent-notification"></h4>
<form id="myForm">
<h2>Send an Email</h2>
<label>Name</label>
<input id="name" type="text" placeholder="Enter Name">
<br><br>
<label>Email</label>
<input id="email" type="text" placeholder="Enter Email">
<br><br>
<label>Subject</label>
<input id="subject" type="text" placeholder=" Enter Subject">
<br><br>
<p>Message</p>
<textarea id="body" rows="5" placeholder="Type Message"></textarea>
<br><br>
<button type="button" onclick="sendEmail()" value="Send An Email">Submit</button>
</form>
</center>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function sendEmail() {
var name = $("#name");
var email = $("#email");
var subject = $("#subject");
var body = $("#body");
if (isNotEmpty(name) && isNotEmpty(email) && isNotEmpty(subject) && isNotEmpty(body)) {
$.ajax({
url: 'sendEmail.php',
method: 'POST',
dataType: 'json',
data: {
name: name.val(),
email: email.val(),
subject: subject.val(),
body: body.val()
}, success: function (response) {
$('#myForm')[0].reset();
$('.sent-notification').text("Message Sent Successfully.");
}
});
}
}
This is my sendEmail.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if(isset($_POST['name']) && isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
require 'vendor/autoload.php';
$mail = new PHPMailer();
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.mail.yahoo.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'atouchof.beauty#yahoo.com'; //SMTP username
$mail->Password = 'aaa'; //SMTP password
$mail->SMTPSecure = 'tsl'; //Enable implicit TLS encryption
$mail->Port = 587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
$mail->isHTML(true); //Set email format to HTML
$mail->setFrom($email, $name);
$mail->addAddress("atouchof.beauty#yahoo.com");
$mail->Subject = ("$email ($subject)");
$mail->Body = $body;
if($mail->send()){
$status = "success";
$response = "Email is sent!";
}
else
{
$status = "failed";
$response = "Something is wrong: <br>" . $mail->ErrorInfo;
}
exit(json_encode(array("status" => $status, "response" => $response)));
}
?>
This may sound confusing so please ask any questions if you don't understand.
Two problems. Firstly you're forging the from address, which is very probably the cause of your problems. This is well documented, and I recommend following the advice given in the PHPMailer contact form example.
A minor issue is that you're setting this to a non-existent value:
$mail->SMTPSecure = 'tsl';
That should be:
$mail->SMTPSecure = 'tls';
You can call multiple times:
$mail->AddAddress('emailONE#gmail.com', 'Juan');
$mail->AddAddress('emailTWO#gmail.com', 'Pepe');
I recommend use https://mailtrap.io/ for testing emails

Php form instead send mail download on computer

<div class="contact_form clearfix" id="Contact">
<h2>Hello... You can send me message to my universe here.</h2>
<img src="img/planeta1.png" alt="">
<form class="clearfix spaceForm" action="contactform.php" metod="post" >
<label for="name">Your name:</label>
<input type="text" name="name" id="name" placeholder="Jon Doe" required>
<label for="email">Your email:</label>
<input type="text" name="email" id="email" placeholder="something#mama.com" required>
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject" required>
<label for="message">Your message:</label>
<textarea name="message" id="message" required></textarea>
<button type="submit" name="submit">Send mail</button>
</div>
and php code here...
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "pisitenam#sammostalnisindikatstark.org.rs";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from " .$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html");
}
?>
My contact form instead to send message download on computer as php file. I uploaded my site to netfly but stil doesnt work.
Can anybody help and give me a hint where is problem?
On XAMPP im getting blank page and mail is not sent. When I uploaded site on netfly site works fine but contact from when click submit start download php file where is code writen for controling contact form.5 day im trying to find solution for this problem and im geting tired :D So if anybody can help...
you are having some spell mistake in your form tag, first of all correct the method spell in your code as it is not correct so it can't redirect and post your data to contact form.
mail library contains various function.
for example:
<?php require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'your_smtp_domain.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
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('john#example.net', 'John doe'); // Add a recipient
$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>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
this can works for you if you use library.

Using PHP to require and modify html content to send as html-email

I am using PHPmailer to send my email. I have created a form that you enter a few details (including the email address). Once I click submit/generate I want to modify the content of the email message using the form details. The email message should show up as an html email. However, I just cannot get my form to display correctly or get my html-email to send correctly.
Form Code (index.php):
`
<?php
//PHP mailer code
require 'PHPmailer/PHPMailerAutoload.php';
$emailmessage = require 'mail.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
if (isset($_POST['submit'])) {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email#email.com'; // 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('email#email.com', 'Me');
$mail->addAddress($_POST['emailrecipients'], $_POST['client']); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['callid'].' | Customer Feedback';
$mail->Body = $emailmessage;
$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';
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form>
<input type="text" id="firstname" name="firstname" placeholder="John" />
<input type="text" id="lastname" name="lastname" placeholder="Doe" />
<input type="email" id="email" name="email" placeholder="email#email.com" />
<button type="submit" name="submit">Generate</button>
</form>
</body>
</html>`
Email Code (mail.php):
<!DOCTYPE html>
<html>
<body>
<p>First Name: <?php $_POST['firstname']; ?></p>
<p>Last Name: <?php $_POST['lastname']; ?></p>
</body>
</html>
I had imagined that upon submitting, the required email message would be altered as per the input fields, then sent to address typed into the the email input field.
I'm not sure if this line works as expected:
$emailmessage = require 'mail.php';
You should have your mail.php as followed:
$emailmessage = "
<!DOCTYPE html>
<html>
<body>
<p>First Name:".$_POST['firstname']."</p>
<p>Last Name: ".$_POST['lastname']."</p>
</body>
</html>";
And then use only
require "mail.php"
in line 2 of your code. You also should add the "form" Tags to your HTML-form.

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