PHPMailer / PHPMailer

The classic email sending library for PHP
GNU Lesser General Public License v2.1
20.77k stars 9.7k forks source link

Not sending email when subject has first and last name in it #3049

Closed RaviWeb105 closed 2 months ago

RaviWeb105 commented 2 months ago

Please check these things before submitting your issue:

Problem description

->when sending email with the name as "Ravi a" the email is not sending ,when sending with "Ravi" email Is sent not accepting the space in name variable which we get from post request

Code to reproduce

   $name = $_POST['name'];
$subject = 'Hello '.$name.'! Welcome to  Habits!';

            $message = '<message body in here>';
   $mail = new PHPMailer\PHPMailer\PHPMailer();
            $mail->IsSMTP();
            $mail->CharSet = 'UTF-8';
            $mail->SMTPDebug = 2;
            $mail->SMTPAuth = true;
            $mail->Host = "host_name";
            $mail->Port = "465";
            $mail->Username = $from;
            $mail->Password = $pass;
            $mail->SMTPSecure = "ssl";
            $mail->From = $from;
            $mail->FromName = "new Apps";
            $mail->AddAddress($to);
            $mail->Subject = $subject;
            $mail->IsHTML(true);
            $mail->Body = $message;
            $mail->Send();

Debug output

in outout we are getting email is sent

Synchro commented 2 months ago

This makes no sense. Your subject line string already has other spaces in, and whether they come from the name or the literal text makes no difference.

First of all double check what you're actually receiving:

 var_dump($_POST['name']);

Then try these combinations to find out where it's going wrong:

$subject = 'Hello Ravi a! Welcome to  Habits!';

$name = 'Ravi a';
$subject = 'Hello '.$name.'! Welcome to  Habits!';

$subject = $_POST['name'];
RaviWeb105 commented 2 months ago

This makes no sense. Your subject line string already has other spaces in, and whether they come from the name or the literal text makes no difference.

First of all double check what you're actually receiving:

 var_dump($_POST['name']);

Then try these combinations to find out where it's going wrong:

$subject = 'Hello Ravi a! Welcome to  Habits!';

$name = 'Ravi a';
$subject = 'Hello '.$name.'! Welcome to  Habits!';

$subject = $_POST['name'];

with $subject = 'Hello Ravi a! Welcome to Habits!';

the emails are not sending

Synchro commented 2 months ago

Define what you mean by "not sending"; show the debug output with $mail->SMTPDebug = 2.

RaviWeb105 commented 2 months ago

Define what you mean by "not sending"; show the debug output with $mail->SMTPDebug = 2.

2024-04-16 10:32:23 SERVER -> CLIENT: 220-p3plzcpnl445408.prod.phx3.secureserver.net ESMTP Exim 4.96.2 #2 Tue, 16 Apr
2024 03:32:23 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2024-04-16 10:32:23 CLIENT -> SERVER: EHLO apis.journyapps.com
2024-04-16 10:32:23 SERVER -> CLIENT: 250-p3plzcpnl445408.prod.phx3.secureserver.net Hello apis.journyapps.com [208.109.22.165]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPECONNECT250-AUTH PLAIN LOGIN250 HELP
2024-04-16 10:32:23 CLIENT -> SERVER: AUTH LOGIN
2024-04-16 10:32:23 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2024-04-16 10:32:23 CLIENT -> SERVER: [credentials hidden]
2024-04-16 10:32:23 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2024-04-16 10:32:23 CLIENT -> SERVER: [credentials hidden]
2024-04-16 10:32:23 SERVER -> CLIENT: 235 Authentication succeeded
2024-04-16 10:32:23 CLIENT -> SERVER: MAIL FROM:<admin@journyapps.com>
2024-04-16 10:32:23 SERVER -> CLIENT: 250 OK
2024-04-16 10:32:23 CLIENT -> SERVER: RCPT TO:<web105@moontechnolabs.com>
2024-04-16 10:32:23 SERVER -> CLIENT: 250 Accepted
2024-04-16 10:32:23 CLIENT -> SERVER: DATA
2024-04-16 10:32:23 SERVER -> CLIENT: 354 Enter message, ending with &quot;.&quot; on a line by itself
2024-04-16 10:32:23 CLIENT -> SERVER: Date: Tue, 16 Apr 2024 10:32:23 +0000
2024-04-16 10:32:23 CLIENT -> SERVER: To: web105@moontechnolabs.com
2024-04-16 10:32:23 CLIENT -> SERVER: From: Journy Apps <admin@journyapps.com>
2024-04-16 10:32:23 CLIENT -> SERVER: Subject: Hello Ravi Amrutiya this is for the test
2024-04-16 10:32:23 CLIENT -> SERVER: Message-ID: <lVheIX7WKUAQiQyAV5JZI9oYaptlTySbPLt2cpzSLcs@apis.journyapps.com>
2024-04-16 10:32:23 CLIENT -> SERVER: X-Mailer: PHPMailer 6.8.0 (https://github.com/PHPMailer/PHPMailer)
2024-04-16 10:32:23 CLIENT -> SERVER: MIME-Version: 1.0
2024-04-16 10:32:23 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2024-04-16 10:32:23 CLIENT -> SERVER: 
2024-04-16 10:32:23 CLIENT -> SERVER: demo
2024-04-16 10:32:23 CLIENT -> SERVER: 
2024-04-16 10:32:23 CLIENT -> SERVER: .
2024-04-16 10:32:28 SERVER -> CLIENT: 250 OK id=1rwg6x-008SCc-2g
2024-04-16 10:32:28 CLIENT -> SERVER: QUIT
2024-04-16 10:32:28 SERVER -> CLIENT: 221 p3plzcpnl445408.prod.phx3.secureserver.net closing connection
{"success":"1","message":"Mail sent successfully!"}
Synchro commented 2 months ago

This shows an entirely successful send. It also reveals that you're using GoDaddy, which is never a good thing, and you're also using an old version of PHPMailer.

RaviWeb105 commented 2 months ago

It also reveals that you're using GoDaddy, ->ya it is used by our client we can't do anything in that.

"This shows an entirely successful send" ->but still we are not receiving the emails

and you're also using an old version of PHPMailer. ->which is the new version nad you mean in new version this is resolved?

Synchro commented 2 months ago

Not receiving and not sending are entirely different problems. PHPMailer is responsible only for sending, and here you have shown that it is working fine; Your submission to GoDaddy's server is successful. What happens to the message after that is nothing to do with PHPMailer, but you should expect to receive bounces if onward delivery from there fails. If you don't receive anything, it's GoDaddy's mail servers that are at fault, which is nothing unusual. Alternatively, check your spam folder.

It's not "resolved" in the new version, because there is nothing to resolve, but you should always be running latest versions.