Show's email success but not receiving email godaddy - php

Hello the phpmailer works when I'm using it on localhost but for some reason when I used a hosting from GoDaddy it won't work anymore.
I already followed almost everything related to this but it seems like I can't find any solution:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$message = "Test";
$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = 'mycpanelusername';
$mail->Password = 'mycpanelpassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 25;
$mail->setFrom('testemail#gmail.com', 'Mailer');
$mail->addAddress($email, 'Joe User');
$mail->addAddress('ellen#example.com');
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = $message ;
$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';
}

You have to use this to actually send the email, at the end:
$mail->send();
And to get more infos:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

Related

How to use phpmailer from sh service framework

I am really stuck in email concept. I used sh service framework for past 3 days i am searching all the way to find how email concept works in sh service especially php mailer.
Thanks and help needed
Use this command :
composer require phpmailer/phpmailer
Follow below procedure:
require 'vendor/autoload.php';
$app->get('/contactus',function($app){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp1.example.com;smtp2.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'user#example.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User');
$mail->addAddress('ellen#example.com');
$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 = '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';
} // Set mailer to
});
it is working fine.
Thanks

in php mailer the smtp connection is failed

I want to send a a mail from local-host to a mail-id. i am using php-Mailer. but its saying that the SMTP connection is failed. can anyone help me please? MY CODE IS BELOW:
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body='hai';
$address='stin#f12technologies.com';
$name='hey';
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "localhost";
$mail->Port = 25;
$mail->Username = "########-####-####-#####-############";
$mail->Password = "########-####-####-#####-############";
$mail->SetFrom('stinjohnece#gmail.com','Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);
if($mail->Send()) {
echo "Message sent!";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
you have to give smtp details
after that bounce(restart) your apache once.
<?php
require dirname(__FILE__) .'/library/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
//$mail->SMTPDebug = 2; // error mode
//$mail->SMTPDebug = 3; // error mode
$mail->isSMTP();
$mail->Host = 'mail.xxx.com';
$mail->SMTPAuth = true;
$mail->Username = 'admin#XXXX.com';
$mail->Password = 'XXXXX';
//$mail->SMTPSecure = 'None';
$mail->Port = 25;
$mail->setFrom('admin#XXXX.com', 'XXXXXX');
//for sending mail
$mail->addAddress($username); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'HAI';
$mail->Body = '<br> <br>
<html><body> <div><div><u><h3>HAI </h3></u></div><div><p>This email has been sent for testing</p><p>xxx<b>xx</b></p><p>xx<b>xx</b></p></div> </body></html>';
$mail->AltBody = 'Unable to display the mail';
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent';
}
?>
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth=true;
//$mail->SMTPDebug=2;
$mail->Host='smtp.gmail.com'; // SMTP server
$mail->Username ='...#gmail.com';
$mail->Password ='...';
$mail->SMTPSecure='ssl';
$mail->Port=465;
$mail->isHTML(true);
PHP mailer docs example
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.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->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');
$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 = '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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

Email not send using PHPMailer

I am a beginner in PHP programming and i have a problem sending email using localhost (Wamp Server) on windows, I looked dozen of answers on this problem but still unable to solve my problem,Is there any problem in my code?
Here is my code
<?php
/**
* Created by PhpStorm.
* User: Farrukh
* Date: 2/19/2016
* Time: 5:09 PM
*/
require "PHPMailer-master/PHPMailerAutoload.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = 'myemail';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->From = 'farrukh#gmail.com';
$mail->FromName = 'FMailer';
$mail->addAddress('myfrien#gmail.com', 'Farrukh');
$mail->WordWrap = 50;
$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->isHTML(true);
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>

PHPMailer sends duplicate email

PHPMailer
<?php
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPSecure = "tls";
$mail->Mailer = "smtp";
$mail->Host = "smtp.office365.com";
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxx";
$mail->Password = "xxx";
$mail->setFrom('xxx', 'Website');
//Send to Admin
$AdminEmail = 'admin.example#gmail.com';
$mail->AddAddress($AdminEmail, $AdminName);
$mail->Subject = "This is an email";
$mail2 = clone $mail;
$body = 'Hi Admin. This is an email';
$mail->Body = $body;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
//Send to User
$UserEmail = 'user.example#gmail.com';
$mail2->AddAddress($UserEmail, $UserName);
$body2 = 'Hi User. This is an email';
$mail2->Body = $body2;
if(!$mail2->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail2->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
I have an issue where when i send the emails, Admin will receive $mail and $mail2 when they supposed to just receive $mail. While there's no problem with User. Works fine by receiving $mail2. I've tried to put $mail->ClearAddresses(); but it's still the same. By chance, what is the problem?
Clone the email variable before adding the address and stuff of the admin. (As suggested in the comments)
You need to create different-different object for both admin and user email
//Send to Admin
$mail = new PHPMailer;
$mail->IsHTML(true);
$AdminEmail = 'admin.example#gmail.com';
$mail->AddAddress($AdminEmail, $AdminName);
$mail->Subject = "This is an email";
$mail2 = clone $mail;
$body = 'Hi Admin. This is an email';
$mail->Body = $body;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
//Send to User
$mail = new PHPMailer;
$mail->IsHTML(true);
$UserEmail = 'user.example#gmail.com';
$mail->AddAddress($UserEmail, $UserName);
$body2 = 'Hi User. This is an email';
$mail->Body = $body2;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

How to setup PHPMailer SMTP

I'm trying to send some mail using php mailer, the boring thing is that one email eas sent the first time and I have no idea what I've done that makes this code to now fail.
ERROR: SMTP server error: authentication required
require("../mailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->From = "site email";
$mail->AddAddress("useremail");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
I'm hosting with GoDaddy.
Thanks to Jake.
Incase someone goes through this again here is what i put in my code.
CODE
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->Username = "email#domain";
$mail->Password = "pwd";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->SMTPDebug = 2; /// i guess this is for reporting...
$mail->From = "email#domain";
$mail->AddAddress("recipient email");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

Categories