setFrom alternative goDaddy - phpmailer

I understand that gmail, yahoo, hotmail etc. etc. won't work with goDaddy and PHPMailer but what email address should I use for setFrom? I would appreciate any help in figuring this out! (I'm trying to have the name and email entered on an html contact form be emailed to me)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
//Set who the message is to be sent from
$mail->setFrom('MY_UNUSABLE_EMAIL', 'MY_NAME');
//Set an alternative reply-to address
$mail->addReplyTo($_POST['email'], $_POST['name']);
//Set who the message is to be sent to
$mail->addAddress('MY_UNUSABLE_EMAIL', 'MY_NAME');
// Content
$mail->Body = <<<EOT
You've recieved a new submission from: {$_POST['name']}.
Their email is: {$_POST['email']}.
EOT;
$mail->Send();
?>

Related

PHPMailer - multiple emails in same Page

My PHPMailer is working perfectly but my problem is that when i receive the different emails from different person´s , all the emails will be received inside the same message (because PHPMailer send emails always from 1 single email (management#gmail.com)).
Its possible to receive always emails in different messages?? Because like that its confused to manage the email.
IMAGEM_EMAIL
email2
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'management#gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->From = $_POST["email"];
$mail->FromName = $_POST["name"];
$mail->addAddress('website#gmail.com');
$mail->AddCC($_POST["email"], $_POST["name"]);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $_POST["subject"];
There is two issues here:
1/ Your gmail/inbox is grouping the mails you receive from PHPMailer. And for that, there is no solution. It's what gmail/inbox do and you can't do anything about that.
2/ You want to hit "reply" to these mails and reply not to "management#gmail.com" but to your user's mail. You can add a "Reply-To" field in mails to achieve that:
$mail->addReplyTo($_POST["email"], $_POST["name"]);

My PHPMailer does not send "any" mail

I've been here since 9:15 AM DETERMINED to find others with the same problem I have. 95% of these PHPMailer look a lot like mine. The main difference is "MINE DOES NOT WORK!!" Please guys, take a "close"look at what I have and tell me where did I go wrong. (My coding below):
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer();
$mail->HOST = "smtp.gmail.com";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "johnm010247#gmail.com";
$mail->Password = "xxxxxxxxxxxxxxxxxx";
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Subject = "Test Email";
$mail->Body = "This Is Our Body.....";
$mail->setFrom("johnm010247#gmail.com", "Robert");
$mail->addAddress("mothers#bcbc-church.org", "Mothers Board");
if ($mail->send())
echo "Mail sent";
?>
I'm using PHPMailer 6.0
PHP is case sensitive for property and variable names.
$mail->HOST = "smtp.gmail.com";
Should be
$mail->Host = "smtp.gmail.com";
It would help if you based your code on the examples provided, since they do not contain basic errors like this.
Aside from that, when posting a question, you need to specify what the problem is; “it doesn’t work” is not enough.

PHPMailer goes to spam

I have problem with PHPMailer. Messages go to spam on o2 and Hotmail. On other servers it works well. Here is my code:
require_once('class.phpmailer.php');
require_once('class.smtp.php');
$mail = new PHPMailer();
$mail->From = "abc#mydomain.pl";
$mail->FromName = "XYZ";
$mail->AddReplyTo('abc#mydomain.pl', 'XYZ');
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.mydomain.pl";
$mail->Mailer = "smtp";
$mail->SMTPAuth = true;
$mail->Username = "abc#mydomain.pl";
$mail->Password = "password";
$mail->Port = 25;
$mail->Subject = "Subject";
$mail->Body = "Message";
$mail->AddAddress ('xxx#yyy.pl','User');
$mail->Send();
Can anyone help?
Apart from the possibility that your server may be blacklisted for some reason, the most common cause for emails landing in spam servers that i encountered is that the from-address and the server's name do not match.
Consider a from-address like someone#mydomain.com sent from a server cheapwebhosting.com, the recipient mail server sees the discrepancy and will most likely consider this a spam message.
So, you should check the message headers of a test email if something like this is happening here (or if you notice anything else that looks fishy)

PHPMailer in combination with Gmail smtp sending mail twice

I have come across some weird behaviour in PHPMailer. I am using my gmail account for the SMTP settings. But every time PHP sends an e-mail(in this case, it's for resetting a password), I receive the same e-mail too. Except for when the password reset is requested for my gmail account.
Here is the code;
//set email settings
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Port = 465;
$mail->Username = 'mymail#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->From = 'noreply#bla.com';
$mail->FromName = 'Bla';
$mail->AddAddress($email); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Bla registration';
$mail->Body ="
<html>
<header><title>Welcome to Bla</title></header>
<body>
<p>Hello,</p>
<p>Welcome to Bla. Thank you for registering an account. Before you can start inventing music, please activate your account</p>
<p><a href='http://www.bla.com/register/activate.php?activation=$activationcode&email=$email'> http://www.Bla.com/register/activate.php?activation=$activationcode&email=$email</a></p>
See you soon on Bla!
</body>
</html>";
$mail->Send();
There is no error or something like that. The e-mail is actually send, and received. Only problem is that I receive as well because the e-mail address in Username is my e-mail address. Does anyone know why this happens?
Add ClearAddresses like this->
$mail->Send();
$mail->ClearAddresses();
And solved.
Greetens
Try to change
$mailer->isSMTP();
to
$mailer->Mailer = 'smtp';

phpMailer with smtp

I have this piece of code:
ini_set('SMTP','smtp.strato.com');
$mail = new PHPmailer();
$mail->IsHTML(true);
It works fine but can I set smtp.strato.com somewhere in phpMailer class?
Have you looked at the smtp example in their site? See here
Unless I'm miss understanding you, it looks to be very straight forward.
$mail = new PHPMailer();
$body = "message";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("whoto#otherdomain.com", "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
You can by changing
$mail->IsSMTP();
$mail->Host = "mail.yourdomain.com";
to
$mail->IsSMTP();
$mail->Host = "smtp.strato.com";
You shouldnt modify the PHPMailer class
//Use this codd to send email using SMTP gmail
<?php
require "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth="login";
$mail->SMTPSecure="ssl";
$mail->Username = "sender#gmail.com";
$mail->Password="password";
$mail->Body="<Body message>";
$mail->MsgHTML=("<h1>Wow Html contents</h1>");
$mail->AddAttachment("Koala.jpg");
$mail->SetFrom("sender#gmail.com","Bucky");
$mail->Subject="My Subject";
$mail->AddAddress("receiver#gmail.com");
if ($mail->Send()){
echo "Sent";
}else
echo "not sent<br>";
echo $mail->ErrorInfo;
?>

Resources