Which PHPMailer prop controls the sender email in the email header? - php

I'm getting an error from jQuery with a 404 to my mail.php (I checked the path and it seems correct)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require("../includes/libraries/phpmailer/PHPMailer-master/src/Exception.php");
require("../includes/libraries/phpmailer/PHPMailer-master/src/PHPMailer.php");
require("../includes/libraries/phpmailer/PHPMailer-master/src/SMTP.php");
$server_email = 'myemail#outlook.com';
$pass = '123456';
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp-mail.outlook.com';
$mail->Port = 587;
$mail->Username = $server_email;
$mail->Password = $pass;
$mail->FromName = $full_name;
$mail->From = $email;
$mail->setFrom($server_email, $full_name );
$mail->addAddress($server_email);
$mail->addReplyTo($email); //email that it will be replied to
$mail->Subject = 'Subscription submitted by ' . $full_name . '.';
$mail->Body = "
Name: $full_name<br><br>
Email: $email<br>
";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
Right now, my email (the outlook one) comes up in the header of the email next to the Sender's Name. The addReplyTo actually does give me the gmail address to reply to, so that's great. But having my email show on the sender header is confusing. See the image below
Thanks in advance

Related

PHP Mailer returns true but email is not received

I'm using PHP Mailer in my website for my contact form.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/PHPMailer/src/Exception.php';
require 'phpmailer/PHPMailer/src/PHPMailer.php';
require 'phpmailer/PHPMailer/src/SMTP.php';
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$message = $_POST['textarea'];
$from = $_POST['email'];
$to = "support#domain.com";
$subject = 'email from website';
$mail = new PHPMailer();
$mail->Host = "smtp.hostinger.com";
$mail->SMTPDebug = 0;
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->Username = $to;
$mail->Password = "mypassword";
$mail->SMTPSecure = "ssl";
$mail->From = $from;
$mail->FromName = $name;
$mail->addReplyTo($from, $name);
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = "Sender": " . $name . " " . $lastname . " \n <br/> Phone: ". $phone ." \r\n <br/> message: " . $message";;
$mail->addAddress($to);
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;
}
else
{
echo 'success';
}
?>
Once I submit the contact form in my website the code above returns success message.
No email is actually received. I have double checked all the $_POST, the values are correct. Also double checked my username and password (I changed them in the question).
What can cause PHP Mailer to return success message and not send the email?
PHP Mailer debug
Sending with mail()<br>
Sendmail path: /usr/sbin/sendmail -t -i<br>
Envelope sender: <br>
To: support#domain.com<br>
Subject: =?UTF-8?B?15nXpteZ16jXqiDXp9ep16gg157XlNeQ16rXqA==?=<br>
Headers: Date: Sun, 19 Sep 2021 09:37:31 +0000From: test11 <test#gmail.com>Reply-To: test11 <test#gmail.com>Message-ID: <sK7qvbbNwmP2IikzBwV7c2mD3TqDUGwEOLeW2HZng#www.reboost.co.il>X-Mailer: PHPMailer 6.5.1 (https://github.com/PHPMailer/PHPMailer)MIME-Version: 1.0Content-Type: text/html; charset=UTF-8<br>
Result: true<br>
You need to tell phpMailer to use SMTP
$mail->isSMTP();
OP replied stating the following error:
Error sending: SMTP Error: The following recipients failed: support#domain.com: <test#gmail.com>: Sender address rejected: not owned by user support#domain.com
This can be caused by having the "from" field differ from the smtp login name.

How to submit a contact form in wordpress using phpmailer and where to redirect it

where to put this configuration code
session_start();
require 'phpmailer/class.phpmailer.php';
require 'phpmailer/class.smtp.php';
$result="";
if(isset($_POST['submit'])){
$to = "username";
$from = "username";
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$company = $_POST['company'];
$subject = $_POST['subject'];
$message = $_POST['msg'];
$msg = 'Full Name : '. $name . " " . "\n\n<br>" . 'Corporate Email : ' . $_POST['email']."\n\n<br>"
. 'Mobile : ' . $_POST['mobile']."\n\n<br>" . 'Company : ' . $_POST['company'] . "\n\n<br>" .
'Subject
: ' . $_POST['subject'] . "\n\n<br>" . 'Message : ' . $_POST['msg'];
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.rediffmailpro.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption`ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom($email, $name);
$mail->addAddress('username', 'Seema User'); // Add a recipient
// Name is optional
$mail->addReplyTo('username', 'Seema');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_post['subject'];
$mail->Body = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send())
{
$result="Something went wrong......";
}
else{
$result="Your inquiry has been submitted, our team will get in touch with you shortly.";
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
Normally we include it in that same file or can make another file to control it but wordpress has it's own rules to control it. Can anyone explain how to use phpmailer code in wordpress step by step.
I would be greatful to you if you will help me.

Using SMTP to send emails in PHP getting blank pge

I am trying to send emails using SMTP Server in Core HP. I am getting a blank page not displaying any errors. Can any one help me out? what i am doing wrong? Unable to check the issue as well!
<?php ob_start();
if(isset($_POST['submit_contact'])) {
require 'PHPMailer/PHPMailerAutoload.php';
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "abc#gmail.com";
$mail->Password = "password1#3";
$mail->SetFrom('$email');
$mail->Subject = $subject;
$mail->Body = $txt;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
}
?>
is your source code located at public_html folder?
In that case you have to include like below
require 'aaa/PHPMailer/PHPMailerAutoload.php';

Cant set sender name phpmailer

So I'm setting up a script to send emails from a contact us form. Everything is working great besides the fact that I can't set sender's name properly. I get an error:
Warning: Creating default object from empty value
My code looks like this:
<?php $eemail = $_REQUEST['email'] ;
$message = $_REQUEST['message']; $subject = $_REQUEST['subject']; $fname =
$_REQUEST['name'];
require("class.phpmailer.php"); $mail = new PHPMailer();
$mail->Username = "email"; // SMTP username
$mail->Password = "password"; // SMTP password $mail->IsSMTP();
$mail->SMTPAuth = true; $mail->Host = 'aspmx.l.google.com';
$mail->Port = 25;
$mail->From = $eemail; $name->FromName = $fname; $mail->Subject =
$subject;
$mail->AddAddress("email", "name");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Body = $message; $mail->AltBody = $message;
if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo
"Mailer Error: " . $mail->ErrorInfo; exit; }
echo "Message has been sent"; ?>
add this code
$mail->SetFrom("$eemail ", "$fname");

GMX contact form

I'm trying to create a simple SMTP-contact form with the help of phpMailer for my homepage but it's not working. It should forward the information of the fields "name, mail, subject, message" to my mailbox (in this case "name, mail, subject, message"). The input fields are also named "name, mail, subject, message" in my html code.
Can anyone tell me what I'm doing wrong? Thanks for any advice.
<?
require('class.phpmailer.php');
require('class.smtp.php');
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->Host = 'mail.gmx.de';
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Mailer = "ssl";
$mail->Password = "****";
$mail->Username = "test#gmx.com";
$mail->SMTPAuth = "true";
$mail->FromName = $_POST['name'];
$mail->AddAddress = $_POST['mail'];
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
if(!$mail->Send())
{
echo 'E-Mail not send.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo "<h5>" . 'Thanks for your message' . "</h5>";
}
?>
The error message says you are missing the recipient address, you have to add one using:
$mail->AddAddress("youemail#youremail.com", "Your Name");
//Your Name is optional. so alternatively you could do:
//$mail->AddAddress("youemail#youremail.com");
The part of the code you reference $mail->Username = "test#gmx.com"; simply sets the username for authenticating with the SMTP server, not the recipient address.

Categories