This is my email.php page coding. Now i'm getting the mail from contact form. But, i can't able to change Reply-To email id. Here, I've added $mail->AddReplyTo($email, 'Reply');. But, it doesn't shows the emailid(contact form sender emailid) in Reply-To option.
I've posted an image here. In quick reply option i can see the receiveing end email id. How can i add a reply to email id(contact form sender emailid)?
<?php
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer;
$name = trim($_POST["name"]);
$typeofmotor = trim($_POST["typeofmotor"]);
$email = trim($_POST["email"]);
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = 587;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email#gmail.com'; // SMTP username
$mail->Password = '1234567890'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->FromName = $name;
$mail->AddAddress('email#gmail.com', ''); // Add a recipient
$mail->AddReplyTo($email, 'Reply');
$mail->AddBCC('');
$mail->WordWrap = 50;
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'subject name';
$mail->Body = "<!DOCTYPE html>
<html lang='en-us'>
<head>
<meta charset='utf-8'>
<title></title>
</head>
<body>
<table width=550 style=\"border: 1px solid #333333;\" border=0 align=center cellpadding=0 cellspacing=0>
</table>
</body>
<html>";
if(!$mail->Send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo '<script type="text/javascript"> alert("Message has been sent"); </script>';
echo '<script type="text/javascript"> window.location = "contact.php"; </script>';
}
?>
Instead of this:
$mail->FromName = $name;
$mail->AddAddress('email#gmail.com', ''); // Add a recipient
$mail->AddReplyTo($email, 'Reply');
Try to use this:
$mail->AddReplyTo($email, 'Reply');
$mail->SetFrom('mailbox#name.com', 'Mailbox name');
$mail->AddAddress('email#gmail.com', '');
Notice:
the reply to addresses needed to be added before the from address
Related
I'm coding a php smtp mail script to send a mail to my users when they lose their password. However it's not working.
The processor always returns:
Message could not be sent...
I've tried it with Gmail smtp and I'm getting the same results.
Can you help? There are two files, the form, and the processor.
Below are the codes:
form:
<html>
<head>
<meta name = 'viewport' content = 'width = device-width, initial-scale = 1.0, maximum-scale = 4.0, user-scalable = yes'>
<link rel = 'stylesheet' href = 'style.css' type = 'text/css'>
<title>Reset Password</title>
</head>
<?php
$db = new PDO('mysql:host=host;dbname=db;charset=utf8', 'user', 'pass');
$sql = $db->query('select id from posts order by id desc');
$row = $sql->fetch(PDO::FETCH_ASSOC);
echo "<a href = 'browse.php?page=".$row['id']."'>Browse</a> <a href = 'index.php'>Home</a>";
echo "<hr>";
echo '<form name = "forgot-pass" action = "reset-pass-notif.php" method = "post">
<label><em>Input your registered email address</em></label><br>
<input type = "text" name = "email"><br>
<em>Enter Image Text:</em><img src="captcha.php" /><br />
<input name="captcha" type="text" /><br>
<input type = "submit" name = "submit" value = "Send Reset-Password Link">
</form>
<hr>
Browse Home';
?>
</html>
processor:
<html>
<head>
<meta name = 'viewport' content = 'width = device-width, initial-scale = 1.0, maximum-scale = 4.0, user-scalable = yes'>
<link rel = 'stylesheet' href = 'style.css' type = 'text/css'>
<title>Reset Password Notification</title>
</head>
<?php
error_reporting(E_ALL);
session_start();
$db = new PDO('mysql:host=host;dbname=db;charset=utf8', 'user', 'pass');
$sql0 = $db->query('select id from posts order by id desc limit 1');
$row0 = $sql0->fetch(PDO::FETCH_ASSOC);
echo 'Browse Home';
echo '<hr>';
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$sql = $db->prepare('select * from users where email = :email');
$sql->bindParam(':email', $email);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
$row = $sql->fetch();
$username = $row['username'];
$user_check = $row['user_hash'];
$subject = 'Reset your Password';
$link = 'http://bquotes.xyz/reset-pass-land.php?username='.$row['username'].'&user_check='.$row['user_hash'].'';
$message = 'Reset your password here: '.$link.' If you cannot click on the link, copy it and paste in your browser address bar';
$sql = $db->prepare('select email from users where email = :email');
$sql->bindParam(':email', $email);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
$row = $sql->fetch();
//require_once ('class.phpmailer.php');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#domain.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('user#domain.com', 'BQuotes Webmaster');
//$mail->addAddress($email); // 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 = $subject;
$mail->Body = $message;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
/*if(!$mail->send()) {
//echo '<em>Message could not be sent. Mailer Error:</em> ', "<em>", $mail->ErrorInfo, "</em>";
echo '<span class = "red"><em>Message could not be sent. You have one or more invalid fields.</em></span>';
} else {
echo '<span class = "green"><em>Message has been sent. Please check your Spam folders if not in Inbox by 10 minutes.</em></span>';
}*/
if (($email)&&($username)&&!empty($_POST['captcha'])&&($_POST['captcha']==$_SESSION['code'])&&($mail->send())){
echo '<span class = "green"><em>Message has been sent. Please check your Spam folders if not in Inbox by 10 minutes.</em></span>';
}
else {echo '<span class = "red"><em>Message could not be sent. You have one or more invalid fields.</em></span>';
}
echo "<hr>";
echo 'Browse Home';
?>
</html>
Thanks!
The correct setting for PHPMailer:
<?php
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "user#domain.com";
$mail->Password = "xxxx";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.domain.com";
$mail->Port = "465";
$mail->setFrom('from#domain.com', 'John Doe');
$mail->addReplyTo('from#domain.com', 'John Doe');
$mail->AddAddress("mailto#otherdomain.com", "Jane Smith");
$mail->CharSet = 'UTF-8';
$mail->IsHTML(true);
$mail->Subject = 'Bla bla or from DB';
$mail->Body = 'Here come the content...';
if (!$mail->send()) {
echo 'Error: ' . $mail->ErrorInfo;
exit;
}
?>
Please use this code .make sure you have given permission in Mail account from you want to send mail.
My Account->Sign-in & security->Allow less secure apps: OFF
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->isSMTP();
$mail->Host = 'smtp.live.com';
$mail->SMTPAuth = true;
$mail->Username = 'mail#gmail.com';
$mail->Password = 'Password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom($details['from'], $details['from']);
if(is_array($details['to'])){
foreach ($details['to'] as $key => $value) {
$mail->addAddress($value['email'], $value['name']);
}
}else{
$mail->addAddress($details['to'], isset($details['name'])?:$details['to']);
}
$mail->isHTML(true);
$mail->Subject =$details['subject'];
$mail->Body =$details['body'];
$mail->send();
Are you running this on localhost? Try Putting off your antivirus for some time. Antivirus tends to block email sending from localhost at times
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
I'm using $.post in my js to check my form and if all is okay, the data will go to my sendinquiry.php which will send the contact form email. All is working just that I can't catch the echo "submitted" to sdata so that I can display the thank you message in jQuery. Anyone?
jQuery
.
.
.
if(errflag > 0){
$('.disclaimer').addClass('errortext');
}
else {
$.post(
"sendinquiry.php",
$('#contact_form').serialize(),
function(sdata)
{
if(sdata == 'submitted') {
var ntext = '<div class="row topbot_m shortwidth"><div class="columns medium-12 text-center"><h3>THANK YOU FOR SUBMITTING YOUR ENQUIRY.</h3><p>Our Sales Representative will contact you shortly.</p></div></div>';
$('#contact_form').hide().html(ntext).fadeIn('slow');
}
}
);
}
PHP
<?php
$subject = "Line Enquiry Form";
$gname = "High Line";
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$contactno = $_POST['contactno'];
$emailadd = $_POST['emailadd'];
$fmessage = $_POST['message'];
require 'PHPMailermaster/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$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 = 'xxx'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($emailadd, $fname);
$mail->addAddress('sender#gmail.com', 'Reza San'); // Add a recipient
$mail->addReplyTo($emailadd, $fname +' '+$lname);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body ="<html>
<head>
<title>".$gname."</title>
</head>
<body>
<h2>".$subject."</h2>
<table>
<tr><td width='200'>First Name: </td><td>".$fname."</td></tr>
<tr><td width='200'>Last Name: </td><td>".$lname."</td></tr>
<tr><td width='200'>Contact No: </td><td>".$contactno."</td></tr>
<tr><td width='200'>Email Address: </td><td>".$emailadd."</td></tr>
<tr><td width='200'>Message: </td><td>".$fmessage."</td></tr>
</table>
</body>
</html>";
if($mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'submitted';
}
?>
I have following piece of code. It returns message "send successfully " but we won't receive email at given gmail, Is this code right or have I missed something?
<?php
require("mailer/PHPMailerAutoload.php");
require("mailer/class.smtp.php");
require("mailer/class.phpmailer.php");
$name=$_POST['Your_Name'];
$email=$_POST['Your_Email'];
$message=$_POST['Your_Msg'];
echo $name ;
$mail = new PHPMailer();
// set mailer to use SMTP
//$mail->IsSMTP();
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = "465";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mandarpatil0003#gmail.com"; // SMTP username
$mail->Password = "Con#Soumitra1"; // SMTP password
// $email is the user's email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST['email'] ;
$mail->From = $email;
// below we want to set the email address we will be sending our email to.
$mail->AddAddress("mandarpatil0003#gmail.com", "Mandar");
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body = $message;
$mail->AltBody ="Name : {$name}\n\nEmail : {$email}\n\nMessage : {$message}";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
else
{
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
?>
Does this code have any problems or do I have to try a different approach?
<?php
include 'library.php'; // include the library file
include "classes/class.phpmailer.php"; // include the class name
include "classes/class.smtp.php";
if(isset($_POST["send"])){
$email = $_POST["email"];
$mail = new PHPMailer; // call the class
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com"; //Hostname of the mail server
$mail->Port = 465; //Port of the SMTP like to be 25, 80, 465 or 587
$mail->SMTPDebug = 1;
//$mail->SMTPAuth = false; //Whether to use SMTP authentication
$mail->Username = "****#gmail.com"; //Username for SMTP authentication any valid email created in your domain
$mail->Password = "****"; //Password for SMTP authentication
$mail->AddReplyTo("****#gmail.com", "Reply name"); //reply-to address
$mail->SetFrom("****#gmail.com", "Your Name"); //From address of the mail
// put your while loop here like below,
$mail->Subject = "Your SMTP Mail"; //Subject od your mail
$mail->AddAddress($email, "Asif18"); //To address who will receive this email
$mail->MsgHTML("<b>Hi, your first SMTP mail has been received."); //Put your body of the message you can place html code here
//Attach a file here if any or comment this line,
$send = $mail->Send(); //Send the mails
if($send){
echo '<center><h3 style="color:#009933;">Mail sent successfully</h3></center>';
}
else{
echo '<center><h3 style="color:#FF3300;">Mail error: </h3></center>'.$mail->ErrorInfo;
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server by Asif18</title>
<meta name="keywords" content="send mails using smpt in php, php mailer for send emails in smtp, use gmail for smtp in php, gmail smtp server name"/>
<meta name="description" content="Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server"/>
<style>
.as_wrapper{
font-family:Arial;
color:#333;
font-size:14px;
}
.mytable{
padding:20px;
border:2px dashed #17A3F7;
width:100%;
}
</style>
<body>
<div class="as_wrapper">
<h1>Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server</h1>
<form action="" method="post">
<table class="mytable">
<tr>
<td><input type="email" placeholder="Email" name="email" /></td>
</tr>
<tr>
<td><input type="submit" name="send" value="Send via SMTP" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Now we are using our own server to send email to our customers. its possible to send email using google server. how to do this. explain with php codes
Download PHPMailer from http://phpmailer.sourceforge.net
Extract to folder phpmailer
Create a file email.php
Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username#doamin.com"; //Reply to this email ID
$email="username#domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
function email($to, $subject, $body){
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "email#domain.com";
$mail->Password = "password";
$mail->SetFrom("anything#domain.com", "Any Thing");
if(is_array($to)){
foreach($to as $t){
$mail->AddAddress($t);
}
}else{
$mail->AddAddress($to);
}
$mail->Subject = $subject;
$mail->Body = $body;
$mail->Send();
unset($mail);
}
Download http://phpmailer.sourceforge.net/ and name it "class.phpmailer.php"
http://micrub.info/2008/09/22/sending-email-with-zend_mail-using-gmail-smtp-services/
http://stackoverflow.com/questions/36079/php-mail-using-gmail