i want to send mail to the client from my site. i am using php sendmail() to send mail.
following is my code :-
<?php
include('Connection.php');
include 'smtp/Send_Mail.php';
if(isset($_POST['submit']))
{
$name = $_POST['userName'];
$mob = $_POST['mobileNo'];
$email = $_POST['emailId'];
$fed = $_POST['feedback'];
$_SESSION['unm']=$name;
$_SESSION['mbl']=$mob;
$_SESSION['eml']=$email;
$_SESSION['fdbk']=$fed;
$sql=" Call addUser('$name','$email','$mob','$fed')";
$result = mysql_query($sql);
$to=$email;
$subject="Thank you for getting in touch.";
$body=' <h1 style="color:blue;"> Dear '. $name.', </h1> <br/>
Thank you for getting in touch';
Send_Mail($to,$subject,$body);
}
?>
and the Send_Mail.php file look like this:
<?php
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "ashmeerafurnishingxxx#gmail.com";
$mail = new PHPMailer();
$mail->IsSMTP(true); // use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "tls://smtp.gmail.com"; // Amazon SES server, note "tls://" protocol
$mail->Port = 465; // set the SMTP port
$mail->Username = "ashmeerafurnishingxxx#gmail.com"; // SMTP username
$mail->Password = "xxxxxxx"; // SMTP password
$mail->SetFrom($from, 'Ashmeera Furnishing Decor');
$mail->AddReplyTo($from,'Ashmeera Furnishing Decor');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
$mail->Send();
}
?>
Its working on localhost bt when i upload the same code on server then the mail was not send.
any configuration settings change required or anything else.
need help ..
thank in advance.
Related
I'm trying to send an email every time someone inputs a form on my website but the SMTP isn't working. It keeps on showing me this error. The credentials of the email account are correct. Also, I have already tried SMTPAuth = False; but still the same result.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// 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);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'TLS';
$mail->SMTPAuth = true;
$mail->Username = 'sender#test.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
//Recipients
$mail->setFrom('test#test.com', ' Services');
$mail->addAddress('recipient#test.com', $name); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Contact Us Message';
$mail->Body = 'Sent a message, This is the message :';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
header('Location: tempage.php');
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
What is going wrong? Thanks for your help.
I'm also struggling 2 days with same issue.
After i find this solution. It's working fine.
Try this.
$mail->Host = 'smtp.office365.com';
change to
$mail->Host = 'smtp.live.com';
I want to implement a feature on form submission It should be able to mail as well It should be stored in Database simultaneously(mail will send both mail id which is specified in form as well as website email).Before asking here I made some of the research but I can find both action individually.I am able to save in Database not able to send mail getting error as SMTP ERROR: Failed to connect to server: (0). For sending a mail I am using PHP mailer. please provide me some guidelines to do it.
code I tried So Far:
//database connection
<?php include_once"config.php"; ?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
include_once "PHPMailer/SMTP.php";
$mail = new PHPMailer();
if (isset($_POST['submit']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$query = "INSERT INTO mail_db(first_name,last_name,email) VALUES
('$fname','$lname','$email');";
$result= mysqli_query($connection,$query);
// print_r($result);
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "mail.website.com";
$mail->Port = 465;
$mail->Username = 'sender#website.com';
$mail->Password ='mypassword';
$mail->setFrom("sender#website.com");
$mail->Subject = 'testForm';
$mail->addAddress("$email");
$mail->Body =
"FirstName"."$fname"."\n".
"LasttName"."$lname"."\n".
"email"."$email"."\n";
$mail->send();
$mail->clearAddresses();
$mail->addAddress("recieve#website.com");
$mail->Body = 'New Registration Details'."\n".
"FirstName"."$fname"."\n".
"LasttName"."$lname"."\n".
"email"."$email"."\n";
$mail->send();
if($mail->send()){
header("Location: thanks.html");
}
else{
echo $mail->ErrorInfo;
}
}
?>
I have used the PHP mailer function to send a mail. This code has worked on XAMPP and 000webhost.com, but its not working on aws.
<?php
require("\PHPMailer\PHPMailer\class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
//$mail->SMTPDebug = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "****#gmail.com"; // Enter your SMTP username
$mail->Password = "************"; // SMTP password
$webmaster_email = $_POST['email']; //Add reply-to email address
$email= "***#gmail.com"; // Add recipients email address
$name= "Recipient's name"; // Add Your Recipient’s name
$mail->From = $webmaster_email;
$mail->FromName = $_POST['name'];
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,$_POST['name']);
$mail->WordWrap = 500; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "website inquiry - Support";
$mail->Body = nl2br($_POST['message']);
$mail->AltBody = nl2br($_POST['message']); //Plain Text Body
if($mail->Send())
echo 1;
else
echo 0;
?>
Please tell me where I am going wrong.
When I am executing this code on aws..its echoing 0
Thanks in advance!
Try with throwing errors by adding "true" to constructor:
try {
new PHPMailer(true);
...your code here...
}
catch (phpmailerException $e) {
echo $e->errorMessage();
}
So perhaps there are some more informations about the error.
I want to send mail through php mail on Amazon SES service, In using PHP Mail But I am not able to send send. I already verify the my email_id. I am using this tutorial as reference http://www.codeproject.com/Articles/786596/How-to-Use-Amazon-SES-to-Send-Email-from-PHP. But It is not sending mail from Amazon SES services, please tell me where I am wrong ?
Previously I was using the same id to send mails from localserver XAMPP. It was working.
sendMail.php
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "Senders_Email_Address";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "Senders_Email_Address"; // SMTP Username
$mail->Password = "MyPassword"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'Senders_Email_Address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
index.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php
require 'sendMail.php';
$to = "Senders_Email_Address";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
</body>
</html>
sendMail.php, class.phpmailer.php, class.smtp.php and index.php are in the same directory.
Neelabh, you are missing something. try following:
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "verified_email address";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "Your_SMTP_Username
"; // SMTP Username
$mail->Password = "SMTP_Password"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'yourdomain.com or verified email address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
Also, create an index file like below:
<?php
require 'Send_Mail.php';
$to = "to#gmail.com";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
Please note that if you have only sandbox access of SES, then the recipient email address also needs to be verified. or you could verify your domain. let me know if this works.
I am trying to setup PHPMailer for a customer. He has his own mail server located at a certain IP address. When asked to give me the information to send email through the system, he gave the following:
Host: xx.xxx.x.x
Port: 25
Domain: mydomain.local
Username: myemail#mydomain.local
Password: <myemailpassword>
From: myemail#anotherdomain.xx
(Which he confirmed is being used for external email sending)
I tried to setup PHPMailer by setting the parameters to the exact namings above.
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "xx.xxx.x.x";
$mail->Port = 25;
$mail->Username = "myemail#mydomain.local";
$mail->Password = <myemailpassword>;
$mail->SetFrom('myemail#anotherdomain.xx', 'Webname');
$mail->[...]
I got the following error:
Failed to connect to server (0)
So I try to send an email through telnet to check if it's the customer's email server or the PHPMailer settings:
telnet xx.xxx.x.x 25
It goes through, I'm connected to the server.
helo mydomain.local
I'm getting 'Hello' as a reply. This leads me to believe it might be the PHPMailer settings that are wrong here.
I also try not using SMTP:
$mail->Host = "ssl://xx.xxx.x.x";
$mail->Port = 25;
$mail->Username = "myemail#mydomain.local";
$mail->Password = "password";
$mail->SetFrom('myemail#anotherdomain.xx', 'Webname');
$mail->[...]
Again no go. Am I going about this wrong? I'm only familiar with setting up PHPMailer to use Gmail before so I'm at a loss as to what could be the issue because I'm using a 'personal' email server.
Thanks Loadparts for your assistance.
I'm still not sure what the issue was but it seems it has resolved itself. It might have been from the email server side because coding wise, I didn't change anything. This is the final code I used.
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Host = "xx.xxx.x.x"; // SMTP server
$mail->Username = "myemail#mydomain.local";
$mail->Password = <myemailpassword>;
$mail->From = "myemail#anotherdomain.xx";
$mail->FromName = <Web_Name>;
$mail->AddAddress("email#domain.com");
$mail->Subject = <Subject>;
$mail->AltBody = <Alt_Body>
$mail->WordWrap = 80;
$body = "test message";
$mail->MsgHTML($body);
$mail->IsHTML(true);
$mail->Send();
I use a test function that I know works 100% to test the email servers when using PHPMailer.
I'm not sure why you are having your problem, but try to use the function I have ( I know it's messy but it does the trick). Just replace all the XXXX with your info and make sure you have both class.phpmailer.php and class.smtp.php in the same folder.
<?php
error_reporting(E_ALL);
$toemail = 'XXXX';
$toname = 'XXXX';
$subject = 'Testing Email Sending...';
$bodyhtml = '<H1>yeah</h1>';
$bodytext = 'heres Hoping it works';
$fromemail = 'XXXX';
$fromname = 'XXXX';
var_dump(sendemail($toemail,$toname,$subject,$bodyhtml,$bodytext,$fromemail,$fromname));
function sendemail($toemail,$toname,$subject,$bodyhtml,$bodytext,$fromemail,$fromname)
{
require_once("class.phpmailer.php");
$mail = new phpmailer();
$mail->IsSMTP();
$mail->From = $fromemail;
$mail->FromName = $fromname;
$mail->Host = "XXXX";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "XXXX"; // SMTP username
$mail->Password = "XXXX"; // SMTP password
$mail->Port="25";
$mail->SMTPDebug=true;
if(strlen($bodyhtml)>0) {
$mail->Body = $bodyhtml;
$mail->IsHTML(true);
}
else if(strlen($bodytext)>0){
$mail->Body = $bodytext;
}
if(strlen($bodytext)>0 && strlen($bodyhtml)>0){
$mail->AltBody = $bodytext;
}
$mail->AddReplyto($fromemail,$fromname);
$mail->Subject = $subject;
// Check if multiple recipients
if(preg_match("/;/",$toemail))
{
$tmp_email=preg_split("/;/",$toemail);
$tmp_contact=preg_split("/;/",$toname);
$mail->AddAddress($tmp_email[0], $tmp_contact[0]);
// echo "<!-- multi email:".$tmp_email[0]." contact:".$tmp_contact[0]." -->\n";
for($j=1;$j<count($tmp_email);$j++)
{
if(preg_match("/\#/",$tmp_email[$j]))
{ $mail->AddCC($tmp_email[$j], $tmp_contact[$j]);
// echo "<!-- multi email cc:".$tmp_email[$j]." contact:".$tmp_contact[$j]." -->\n";
}
}
}
else{
$mail->AddAddress($toemail, $toname);
}
$error= false;
if($mail->Send()){
$error =true;
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
return $error;
}
If this doesn't work, my first try would be using port 80 - which usually isn't blocked, then you can work on getting SSL to work.
PS: because it's a local domain, you may want to consider adding the domain to your /etc/hosts just to be sure.
Best of Luck!