Sending Email by PHPmailer without SMTP - phpmailer

I know that we could use PHPMailer to send an email without the need of SMTP. But I still don't understand how it is configurated.
1/ Can we set anything to "Email From"? If so then anybody could fake an email address and send it to anybody? If not what is the condition?
2/ What is the basic configuration that a Web server must have in order for it to work.
Sorry for my silly questions.
<?php
$mail = new PHPMailer(true);
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("britney#britneyspears.com", "Britney Spears");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
?>

I am not familiar.
see. https://github.com/PHPMailer/PHPMailer
1/ Can we set anything to "Email From"?
You can use setFrom . (https://github.com/PHPMailer/PHPMailer#a-simple-example)
$mail->setFrom('from#example.com', 'Mailer');
If so then anybody could fake an email address and send it to anybody?
uhhh... I think SMTP server has error.
PHPMailer use $from. maybe $from was setted by setFrom . (https://github.com/PHPMailer/PHPMailer/blob/master/src/SMTP.php#L817)
If not what is the condition?
If address doesn't set, I think error will occur. (https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L1185)

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

HTML showing as plain text body in PHPMailer

I feel embarassed to ask this because I have seen this question asked several times. However none of the solutions seem to be working for me. My HTML is output as plain text in the body of e-mail sent through PHPMailer
I have read the PHPMailer documentation on Github and found answers like this PHPmailer sending HTML CODE and this Add HTML formatting in phpmailer on stackoverflow.
//Create a new PHPMailer instance
$mail = new PHPMailer(true);
// Set PHPMailer to use the sendmail transport
$mail->isSendmail();
//Set who the message is to be sent from
$mail->setFrom('xxx#yyy.com');
//Set an alternative reply-to address
// $mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('xxx#yyy.com');
//Set the subject line
$mail->Subject = 'Rework Report';
$body = file_get_contents('current/rework.txt');
$mail->Body= $body;
$mail->IsHTML = (true);
//Attach a file
//$mail->addAttachment('current/rework.txt');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
The output should be HTML in the body of the e-mail.
As per the PHPmailer sending HTML CODE link in your question, you likely need to change:
// From
$mail->IsHTML = (true);
// To -- i.e. remove the equals sign (=)
$mail->IsHTML(true);
As it appears to be a function as opposed to a variable.

from header in PHPMailer

Im using PHPMailer to send emails. Now I have a contact form and when a user fills it out I should receive an email. In the email, when I click reply I'd like to have customer email in there, however im getting my own server email. I also want the email to say 'from: customer#hisemail.com' (customer email).
I believe i have to setup headers here. However I couldn't find any info about PHPMailer headers... Maybe someone could give me an advice? Thanks!
Here is my code:
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Sender = $email;
$mail->From = 'myemail#myserver.com';
$mail->FromName = $fullname;
$mail->MsgHTML($question);
$mail->AddAddress($mailmanager, "support");
$mail->AddReplyTo($email, $fullname);
if(!$mail->send()) { echo 'mail not sent'; }
Don't do that. It will fail to deliver on most ISPs because you are trying to forge the from address. Instead, send from your own address and add the customer's address as a reply-to address:
$mail->addReplyTo($customeremail);

Awardspace Email Setting

I got a Award Space Mail Hosting account.I created that account only for the free email sending feature.
Tried
PHP mailer
swiftmailer ect..
But no use.Can anyone give me a full working code of php and mail form,so that i can just test it in my server .I cound send emails when using this file :
http://www.html-form-guide.com/php-form/php-form-validation.html
But,i dont want that peace of code.I want a perfect code that can work on My server.
Sample code:(Has an html form submit form)
<?php
if(isset($_POST['submit'])) {
$myemail = “support#domain.dx.am”;
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
echo “Your message has been sent successfully!”;
mail($myemail, $subject, $message, $headers);
} else {
echo “An error occurred during the submission of your message”;
}
?>
Or i tried doing the same with php mailer:
<?php
require 'filefolder/mailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support#whatever.dx.am'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->From = 'support#whatever.dx.am';
$mail->FromName = 'Support';
$mail->AddAddress('anything#gmail.com'… // Name is optional
$mail->WordWrap = 50; // Set word wrap to 50 characters
$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;
exit;
}
echo 'Message has been sent';
?>
I am doing something wrong. But cant figure out what. Can anyone help me out .
The 'from' header should be an existing email account inside your Email Manager of your Hosting Control Panel.
as their FAQ says:
Tip: Please note that the 'From' header should be an existing email account inside your Email Manager of your Hosting Control Panel.
FAQ

Signing PHP emails on shared hosting

I am on a shared hosting plan, and when I send emails with PHP, email clients (like Gmail) will add a little via bit to my from field, with my host's domain in there.
So instead of my emails being just from my domain:
From: me#mydomain.com
It's from two domains:
From: me#mydomain.com via host13.myhost.com
Clearly, this is confusing to people receiving email and is poor branding. Since I'm on a shared hosting plan, I don't think I'm likely to have access to the configurations settings of PHP or whatever it uses to mail. Is it possible for me to digitally sign my PHP emails, or is this not possible on shared hosting?
Here is what I'm doing now:
$header = "From: me#mydomain.com";
mail("you#yourdomain.com", "subject", "body", $header);
You can try this, you need to download the PHP Mailer class from Here and your code will be like this:
<?php
include "PHP MAILER CLASS";
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->AddAddress("Reciever Email", "Reciever Name");
$mail->SetFrom('Sender Email', 'Sender Name');
$mail->Subject = "Subject";
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("Message Body");
$mail->Send();
} catch (phpmailerException $e) {
$e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
?>
The default mail function is at the mercy of your server setup and rarely looks like regular mail to the reciever. You should use a library either SwitfMailer or pear MAIL that can send the mail through your own mail server via SMTP. You can use your normal email account or setup a new one for your web service.

Resources