PHPMailer shows weird character [duplicate] - php

My code works but when I send an Email I see this long block on informations that starts like this:
2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
...and goes on writing al the informations about PHPMailer.
I don't want everyone to see it after they send an Email, how can I hide it?
that's my code:
if($errore == 0){
$message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
$message_email .= 'Email: '.$email.'<br>';
$message_email .= 'Telefono: '.$number.'<br>';
$message_email .= 'Oggetto: '.$object.'<br>';
$message_email .= 'Corpo: '.$message.'<br>';
require 'PHPMailer.php';
require 'Exception.php';
require 'SMTP.php';
$mail = new \PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('bibibibi#gmail.com');
$mail->addAddress('lalala#gmail.com');
$mail->msgHtml($messaggio_email);
$mail->Subject = $object;
if(!$mail->Send()) {
echo "something went wrong";
var_dump($mail);
} else {
echo 'Email sent';
}

You need to change the "SMTP class debug output mode." using the SMTPDebug property.
$mail->SMTPDebug = SMTP::DEBUG_OFF;
Your actual value (1) corresponding to DEBUG_CLIENT.
But you should use one of the following allowed values :
SMTP::DEBUG_OFF: No output
SMTP::DEBUG_CLIENT: Client messages
SMTP::DEBUG_SERVER: Client and server messages
SMTP::DEBUG_CONNECTION: As SERVER plus connection status
SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

Related

How can i sent mail using PhpMailer in 000webhost but it working in before Hosting?

Error/SMTP Debug
I am using free Hosting
These are the errors shown in the SMTP debug,
I tried all the error rectifying method
2021-06-09 10:48:28 CLIENT -> SERVER: EHLO pro-online-grocery-store.000webhostapp.com
2021-06-09 10:48:28 CLIENT -> SERVER: STARTTLS
2021-06-09 10:48:28 CLIENT -> SERVER: EHLO pro-online-grocery-store.000webhostapp.com
2021-06-09 10:48:28 CLIENT -> SERVER: AUTH LOGIN
2021-06-09 10:48:28 CLIENT -> SERVER: [credentials hidden]
2021-06-09 10:48:28 CLIENT -> SERVER: [credentials hidden]
2021-06-09 10:48:29 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu534-5.7.14 r9miUOgrMuntYtRkI3wx89ZiLPDiYDroneH6_Ac89byfZeSU2gtMewvVSN-TnwnTEsK2X534-5.7.14 X6W1XKlpqvOKd-K2MZpowZc693zGaaoSyXDK15XQ5QE-ox79_jKysPinbpuBFaXB>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 v17sm12296941qta.77 - gsmtp
SMTP Error: Could not authenticate.
2021-06-09 10:48:29 CLIENT -> SERVER: QUIT
SMTP Error: Could not authenticate.
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/353/16879353/public_html/vendor/phpmailer/phpmailer/src/SMTP.php:278) in /storage/ssd3/353/16879353/public_html/function_db.php on line 36
My PhpMailer code
I think my code is correct because it works perfectly in local host and dont know why it is not working
<?php
session_start();
require 'db.php';
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
function mailTo($to, $user, $subject, $body, $success, $error)
{
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '***************#gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('saigrocery#gmail.com', 'onlineshopping');
$mail->addAddress($to, $user);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
if ($mail->send()) {
header($success);
}
} catch (Exception $e) {
header($error);
}
}
?>

How to hide the logs of PHPMailer?

My code works but when I send an Email I see this long block on informations that starts like this:
2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
...and goes on writing al the informations about PHPMailer.
I don't want everyone to see it after they send an Email, how can I hide it?
that's my code:
if($errore == 0){
$message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
$message_email .= 'Email: '.$email.'<br>';
$message_email .= 'Telefono: '.$number.'<br>';
$message_email .= 'Oggetto: '.$object.'<br>';
$message_email .= 'Corpo: '.$message.'<br>';
require 'PHPMailer.php';
require 'Exception.php';
require 'SMTP.php';
$mail = new \PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('bibibibi#gmail.com');
$mail->addAddress('lalala#gmail.com');
$mail->msgHtml($messaggio_email);
$mail->Subject = $object;
if(!$mail->Send()) {
echo "something went wrong";
var_dump($mail);
} else {
echo 'Email sent';
}
You need to change the "SMTP class debug output mode." using the SMTPDebug property.
$mail->SMTPDebug = SMTP::DEBUG_OFF;
Your actual value (1) corresponding to DEBUG_CLIENT.
But you should use one of the following allowed values :
SMTP::DEBUG_OFF: No output
SMTP::DEBUG_CLIENT: Client messages
SMTP::DEBUG_SERVER: Client and server messages
SMTP::DEBUG_CONNECTION: As SERVER plus connection status
SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

Facing errors while sending mail in local server

I am unable to send an email on my local server.
I used following phpmailer code to test mail sending:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 587; // SMTP port
$mail->Username = ""; // username
$mail->Password = ""; // password
$mail->SetFrom('', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But I get the following error:
2020-07-06 09:20:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y7sm6517117pjy.54 - gsmtp
2020-07-06 09:20:08 CLIENT -> SERVER: EHLO localhost
2020-07-06 09:20:08 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [157.49.67.14]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-07-06 09:20:08 CLIENT -> SERVER: STARTTLS
2020-07-06 09:20:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2020-07-06 09:20:09 CLIENT -> SERVER: QUIT
2020-07-06 09:20:09
2020-07-06 09:20:09
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please suggest possible solutions.

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

2018-03-05 18:25:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP
o5sm27821483pfh.51 - gsmtp 2018-03-05 18:25:08 CLIENT -> SERVER: EHLO
localhost 2018-03-05 18:25:08 SERVER -> CLIENT: 250-smtp.gmail.com at
your service, [43.247.156.6]250-SIZE
35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 2018-03-05 18:25:08 CLIENT -> SERVER: STARTTLS 2018-03-05
18:25:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS SMTP Error:
Could not connect to SMTP host. 2018-03-05 18:25:09 CLIENT -> SERVER:
QUIT 2018-03-05 18:25:09 2018-03-05 18:25:09 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message
has been sent
my code is
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'girish8134#gmail.com'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('girish8134#gmail.com', 'Giri');
$mail->addAddress('girish3055#gmail.com', 'giri3055'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message bod';
$mail->AltBody = 'This is the body is';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
first try this> https://support.google.com/accounts/answer/1064203?hl=en
Disabling two step authentication.
If it doesn't work like that, you can always try and simplify some code (and try ssl - port 467):
$mail->setFrom('girish8134#gmail.com');
$mail->addAddress('girish3055#gmail.com');
Let me know if it worked.
Try this:
$mail->SMTPSecure = 'ssl'; // Use SSL encryption,
$mail->Port = 465 // change port to 465

PHP Mailer Error: Mail Address Not Valid

I would like to send an email using Gmail SMTP server through PHP Mailer.
I am running Zend Server Community Edition in my machine.
Following is my code (edited to hide certain confidential information).
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = "test msg";
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->Username = "<valid-id>";
$mail->Password = "<valid-password>";
$mail->SetFrom('a#b.c', 'Name');
$mail->AddReplyTo("a#b.c","Name");
$mail->Subject = "subject";
$mail->MsgHTML($body);
$address = "d#e.f";
$mail->AddAddress($address, "halo:);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
Despite following thoroughly the example from PHP Mailer wiki page, I somehow couldn't manage to send the email accordingly.
This is the error message generated by the function:
SMTP -> ERROR: Failed to connect to server: A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond. (10060) The following From address failed:
a#b.c Mailer Error: The following From address failed: a#b.c
Please advise me regarding this matter. Thank you.
have you tried:
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
I have changed in your code my emails, my smtp user, my settings ^^^, password and the line:
$mail->AddAddress($address, "Mihai"); // you forgot a quote
used PHPMailer5.2.1 and result:
SMTP -> FROM SERVER:220 mx.google.com ESMTP gq2sm2073759bkc.13
SMTP -> FROM SERVER: 250-mx.google.com at your service, [***.***.***.***] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK gq2sm2073759bkc.13
SMTP -> FROM SERVER:250 2.1.5 OK gq2sm2073759bkc.13
SMTP -> FROM SERVER:354 Go ahead gq2sm2073759bkc.13
SMTP -> FROM SERVER:250 2.0.0 OK 1345113839 gq2sm2073759bkc.13
Message sent!
Mail received:
X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/)

Categories