PHPMailer ismail not working in bluehost - php

I am usng bluehost as server of my domain. I am using below code for sending mail using PHPMailer. The code does not through error and confirms that the mail has gone. But actually the mail does not go to recipient. can anyone suggest what is wrong here?
$Recpnt1='abc#gmail.com';
$emailfrom = 'xyz#AlphaBeta.com';
require_once 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
//From email address and name
$mail->From = $emailfrom;
$mail->FromName = "AlphaBeta";
//To address and name
$mail->addAddress($Recpnt1);
//Send HTML or Plain Text email
$mail->isHTML(true);
// Your subject
$mail->Subject = "Your confirmation link here";
$message='ABCD';
$mail->Body = $message;
if($mail->send())
{
$error = $error . "Confirmation link Has Been Sent To Your Email Address.";
}
else
{
$error = $error . 'Cannot send Confirmation link to your e-mail address';
}

Related

How to addCC and addReplyTo for multiple email addresses?

I'd like to use this send.php script for a contact form. Right now when an email is sent, a user inputs their name, email, and the email of the person to send the email to.
The email is sent from #Email_Placeholder and both #Email_Placeholder, $email, and #email_2 gets a copy of the email.
I'd like to add the option for an addReplyTo and addCC so that both $email and $email_2 receives an email when either of the 3 parties makes a reply to the original email thread.
What is the correct syntax so that $email, and $email_2 are added to the addReplyTo and addCC parameters so that they receive every email in the original thread?
//Lines to edit. Goal add $email and $email_2 to addReplyTo and addCC
$mail->addReplyTo('#Email_Placeholder', 'Information');
$mail->addCC('#Email_Placeholder'); //should be changed to the name of the app owner's email
Send.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); //sanitize data
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$email_2 = filter_var($_POST['email_2'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
/*added line of code*/
if(empty($name)){
header("location: index.php?nouser");
exit();
}
if(empty($email)){
header("location: index.php?noemail");
exit();
}
if(empty($message)){
header("location: index.php?noemail");
exit();
}
/*if(empty($message)){
header("location: index.php?nomessage");
exit();
}//end validation*/
//added line; 'honeypot'
if(empty($_POST['phone2'])){
//Information that needs to be filled out to be able to send an email through phpmailer
//Will use an SMTP service. SMTP is basically like a mail server to send mail
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 1;
//$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = "25";
$mail->Username = "#Email_Placeholder";
$mail->Password = "Password";
$mail->SetFrom("#Email_Placeholder");
$mail->setFrom('#Email_Placeholder', 'Greeting');
// Add a recipient : used to also send to name
//This sends an email to both $email and $email_2
$mail->addAddress($email);
$mail->addAddress($email_2);
//This makes it so that #Email_Placeholder receives a copy of the emails
$mail->addReplyTo('#Email_Placeholder', 'Information');
$mail->addCC('email#gmail.com');
/*$mail->addBCC('bcc#example.com');*/
//Body content
$body = "<p><strong>Hello, </strong>" . $email . " How are you?
<br>
<b> Please Notice: </b><br>
<br> <br> Your message was Delivered: " . $message . ". Hello" . $name2 .
"</p>";
$mail->isHTML(true);
//subject line of email
$mail->Subject = $name;
//for html email
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
//the email gets sent
header("Location: http://www.test-domain.com");
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>

Unable to send email from godaddy server to godaddy or zoho mail

I am trying to send email from my website to my godaddy mail and zoho mail but its not working.
I tried it on my gmail account and its working fine.
I am using phpmailer.
MY CODE-
require_once "PHPMailerAutoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "test#deltware.com";
$mail->FromName = "Himanshu Mishra";
$mail->addAddress("my godaddy webmail"); //Recipient name is optional
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
Please help!!!!!
Your From syntax is wrong
Instead of
$mail->From = "test#deltware.com";
$mail->FromName = "Himanshu Mishra";
It should be
$mail->setFrom('test#deltware.com', 'Himanshu Mishra');
Check this link https://github.com/PHPMailer/PHPMailer

Trying to create a php auto email after a form has been submitted, and style the email with HTML

I'm building a form that allows someone to sign up for a deal. I want the form to send 3 emails using php once it has been submitted; one sending the details of the form to myself, one sending the details to the person offering the deal, and one sending the actual deal confirmation and voucher to the person who signed up.
I've run into problems in that certain email addresses don't seem to receive or be sent the email when i'm testing it (it works for both my hotmail and gmail addresses, but not for my own domain email address). I also can't figure out how to add some sort of html style to the emails being sent.
How can I style these emails and make sure that they are being sent to right email addresses?
here is the code:
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$airline=$_REQUEST['airline'];
$position=$_REQUEST['position'];
$checkin=$_REQUEST['checkin'];
$attendance=$_REQUEST['attendance'];
$email=$_REQUEST['email'];
$terms=$_REQUEST['terms'];
if (($name=="")||($position=="")||($checkin=="")||($attendance=="")||($email==""))
{
echo "All fields are required, please fill the form again.";
}
//email going to me//
else{
$from="From: Deal 1 Form Submission<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("myemail#test.com",
$subject,
$message="someones taken the deal: heres their info: <br> Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n" );
echo "Email sent!";
}
//email going to the customer//
{
$from="From: me<myemail#test.com>\r\nReturn-path: $email";
$subject="Thank you for choosing this deal";
mail("$email", $subject, $message="thanks for choosing this deal!, please present this voucher when attending the restaurant", $from );
}
//email going to the partner//
{
$from="From: Me<myemail#test.com>\r\nReturn-path: $email";
$subject=" Great news! Someone has chosen your deal";
mail("partneremail#test.com",
$subject,
$message="Fantastic news, a customer has taken your deal! here's their info: Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n
", $from );
}
}
?>
Many thanks.
Your best bet is to use PHPMailer. Here is some example code that relays the email through gmail. The reason why you would want to do this is to avoid emails from the server going into you spam box.
$debug = true; // set it to false in production
$Mail = new PHPMailer();
if ($debug) {
// this allows you to see the details of the connection to gmail
$Mail->SMTPDebug = 4;
}
$Mail->isSMTP();
$Mail->Host = 'smtp.gmail.com';
$Mail->SMTPAuth = true;
$Mail->Username = 'your#gmail.com';
$Mail->Password = '[your-password]';
$Mail->SMTPSecure = 'tls';
$Mail->Port = 587;
$Mail->setFrom('from#address.com', 'John Smith');
$Mail->addAddress('to#address.com', 'Someone Else');
$Mail->addReplyTo('from#address.com', 'John Smith');
$Mail->addBCC('bcc#address.com', 'BCC Person');
$Mail->addAttachment('path/to/img/or/pdf/or/whatever/you/want/to/attach.pdf');
$Mail->Subject = 'Test Subject';
$Mail->Body = '<h1>Hi! This is an HTML format body'
$Mail->AltBody = 'Hi! Im just a text email in case HTML is not supported!';
if (!$Mail->send()) {
print $Mail->ErrorInfo;
return false;
} else {
return true;
}

i am submitting my form with php but it is going to spam

**> the mail posted with the below given is going to spam. I am not using
captcha in the form as i don want to. So can anybody help me to the
mail in Inbox**
<?php
if(isset($_POST['submit']))
{
$name = $_POST['Name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$date = $_POST['checkinDate'];
$package = $_POST['package'];
$person = $_POST['adults'];
$kids = $_POST['kids'];
$ip=$_SERVER['REMOTE_ADDR']; //trace the ip address of the user submited
$subject ="Query From :Kerala-Honeymoon-Packages - Promotion\n"; //subject of the email
$to="paul#roverholidays.com";
$cc="online#roverholidays.com";
$ccc="deepti#roverholidays.com";
$from=$_POST['email'];
$adc="Name :$name\n";
$adc.="Email :$email\n";
$adc.="Phone :$phone\n";
$adc.="Date of Travel :$date\n";
$adc.="Package :$package\n";
$adc.="Adults :$person\n";
$adc.="Kids :$kids\n";
$message ="$name copy of the query you submited in Kerala-Honeymoon-Packages";//message header to user submited
$headers="From: <".$from. ">" ;
mail($cc,$subject,$adc,$headers);
mail($ccc,$subject,$adc,$headers);
mail($email,$message,$adc);
header("Location: thanks.htm");
}
else
{
return false;
}
?>
coding-wise I don't think there is anything you can do because it is the email server that classifies your email as a spam not the way you coded your script. All you can do is to control it from the receiver email setting i.e you setup your gmail filters to detect that email based on keyword like "Kerala-Honeymoon-Packages" and move it out of spam.
I don't know for sure what the email servers algorithms are for marking email as spam. However, I think sending email from different domain rather than your domain name is likely to be detected as phishing email. what I mean is when someone put his/her yahoo email in the form and click on send, your server will send the email to emails addresses in the script but it will send it as if it came from yahoo, which will be suspicious for the receiver email server as it knows that it did not come from yahoo.
Many email services block mail sent directly from random servers because they have little to no reputation as a legitimate source of non-spam emails. Instead of using the straight php mail() function, try using a SMTP service like Mandrill or Gmail's SMTP service. Both are free.
Here is the configuration page for Mandrill:
http://help.mandrill.com/entries/23737696-How-do-I-send-with-PHPMailer-
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh#example.net', 'Josh Adams'); // Add a recipient
$mail->AddAddress('ellen#example.com'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$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;
exit;
}
echo 'Message has been sent';

PHPMail - can I send two unique emails

I'm using PHPMailer to successfully send an email upon a webform submission (so just using basic post data, no mysql databases or any lookups).
What I need to do is send two seperate emails, one version for the customer and the other for a customer service agent - so that when a user completes a webform, they will receive a 'marketing' version of the email, whilst the customer service agent will receive an email just containing the details submitted by the user.
See below what im using at the moment, but not sure how to best implement to send the secoind email? It presently fails and the script exits after sending only one email.
$body = ob_get_contents();
$to = 'removed';
$email = 'removed';
$fromaddress = "removed";
$fromname = "removed";
require("phpmailer.php");
$mail = new PHPMailer();
$mail->From = $fromaddress;
$mail->FromName = $fromname ;
$mail->AddAddress("email#example.com");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject";
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
if(!$mail->Send()) {
$recipient = 'email#example.com';
$subject = 'Contact form failed';
$content = $body;
mail($recipient, $subject, $content,
"From: mail#yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
//Send the customer version
$mail=new PHPMailer();
$mail->SetFrom('email', 'FULLNAME');
$mail->AddAddress($mail_vars[2], 'sss');
$mail->Subject = "Customers email";
$mail->MsgHTML("email body here");
//$mail->Send();
In the customer version you are not setting the email's properties the same way you are in the first. For example you use $mail->From = $fromaddress; in the first and $mail->SetFrom('email', 'FULLNAME'); in the second.
Because you instantiated a new $mail=new PHPMailer(); you need to set the properties again.
Instead of just bailing out with a useless "something didn't work" message, why not have PHPMailer TELL you what the problem is?
if (!$mail->send()) {
$error = $mail->ErrorInfo;
echo "Mail failed with error: $error";
}

Categories