My PHPMailer does not send "any" mail - phpmailer

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.

Related

phpmailer send mails via OWN mailserver, missing DKIM

i'm using phpmailer V 6.6.0
Here at stackoverflow are a lot of hints and tricks, how to create and use key files for sending DKIM-signed mails.
But my problem is very simple.
I can't remember to provide Thunderbird / Livemail / Outlook whatever with a .key-file.
All i want to do is to use phpmailer sending a mail via my mail server. Like all other EMail-Programs do.
This is my code so far:
$Server = "xxxxxx.xxxxxx.com" ;
$Username = "mxxxxx" ;
$Password = "xxxxxxxxxxxx" ;
$mail = new PHPMailer();
$mail->isSendmail();
// Define the sender
$mail->Host = $Server;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = $Username;
$mail->Password = $Password;
$mail->Hostname = "#thisdomain.com";
$mail->MessageID = "<".time()."#thisdomain.com>";
$mail->XMailer="MyMailer";
//Set who the message is to be sent from
$mail->setFrom($dbset['Sender']);
$mail->addReplyTo($dbset['Sender']);
$mail->addAddress($dbset['Receiver']);
$mail->Subject = "JUST A TEST";
$mail->isHTML(false);
$mail->Body = "This is just a test";
//send the message, check for errors
$Res = $mail->send();
if (!$Res) die('VERY BAD - Error sending mail!');
$mail->__destruct();
unset($mail);
Well it works great, beside of the "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=badeba3b8450; t=1652648844;
bh=x8/D1v6jj+heUcnMHbgz3HeVzmgGNIkhaOk...lots of bytes here..."
What am i doing wrong?
I don't need to set up an own mail server.
My mail server at my provider works great, including the DKIM signature.
Why won't it work with phpmailer?
Signing the Email is not the job of the client, it should be done at the mail server.
Or i'm wrong at this?
Helpless
Mac

setFrom alternative goDaddy

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();
?>

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"]);

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 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