How do I change the console log? - php

I use php to send email. It works perfectly, but I don't like that it outprints everything on the screen. I want this commant to remain silent. What should I do?
The command is the following:
verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '************#gmail.com'; // SMTP username
$mail->Password = '*********'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
//Recipients
$mail->setFrom('*********', 'Mailer');
$mail->addAddress('**************.com');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Want to get not';
$mail->Body = $_SESSION['nyelv'];
$mail->AltBody = $_POST['email1'];
$proba = $mail->send();

Related

PHPmailer with AWS SES

I am trying to send emails through PHPmailer using the AWS SES SMTP account.
Somehow it sends emails when I ping the file from the terminal but fails to do so when I hit the same file from the browser. Below is the code.
$mail->isSMTP();
$mail->setFrom($sender, 'xx#site.com');
$mail->Username = USERNAME;
$mail->Password = PASSWORD;
$mail->Host = 'email-smtp.us-east-1.amazonaws.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 4;
$mail->SMTPSecure = 'tls';
$mail->addAddress('xx#gmail.com');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $bodyHtml;
$mail->AltBody = $bodyText;
$mail->Send();
The error in the browser says: SMTP Error: Could not connect to SMTP host.

Use `addStringAttachment` and `addEmbeddedImage` in a mail to MS Outlook

I have been trying to send emails with an attachment using PHPMailer. This worked fine. Then I decided to embed an image using the addEmbeddedImage-method.
Now I have a problem! The emails are received fine in gmail. But when I open the email in windows (using MS-Outlook) the attachment disappears!!
$mail = new PHPMailer;
//Server settings
$mail->SMTPDebug = 0; // Disable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailUserName; // SMTP username
$mail->Password = $mailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($mailSentFrom , $organisation);
$mail->addAddress($emailAdress, $recipientFullName);
//Attachments
$mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'].PHP_PATH.'/library-overrides/FPDF/images/small-logo.jpg', 'logo');
$mail->addStringAttachment($attachment, "$categoryName $seasonName, $recipientFullName.pdf", 'base64', 'application/pdf');
$mail->isHTML( true );
$mail->Subject = "$categoryName $seasonName";
$mail->Body = ""; // contains html version of email (omitted for readability)
$mail->AltBody = "";
$mail->send();
Any ideas how to fix this?

PHPmailer : Showing a weird text before sending a mail?

My problem is clear, PHPmailer is howing a long text before sending a mail, this is my code (function) :
function sendMail($content){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Port=465; // Enable SMTP authentication
$mail->Username = 'my mail'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug=true;
$mail->From = '****';
$mail->FromName = '******';
$mail->addAddress('******');
$mail->Subject = 'subject';
$mail->Body=$content;
$mail->AltBody ='testing';
$stat=$mail->send();
}
and this is a screenshot :
http://i.imgur.com/kLrC97q.jpg
Thanks
Sorry guys, I noticed that I should turn off debugging :
$mail->SMTPDebug=false;

PHPMailer - make the sender mail variable

I'm using php mailer and i cant specify the sender mail , i want to be a variable every one type his email to be here , but it cant be done i must type my email and my password , so anyone know how it can be done
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.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"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "usermail"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->addReply=$_POST['email'] ;
$mail->addAddress=$_POST['email'];
$mail->Subject=$_POST['subject'];
$mail->Body=$_POST['message'] .$_POST['email'];
$mail->Sender=$_POST['email'];
try this code
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
#$mail->Send()
Go through this link -> Own-Email-System-using-SMTP-and-PHPMailer
OR,
Please elaborate your issues so that i can help you properly .
NOTE:If "Less secure app access" is turned off for your Gmail account, you have to turn it on. => Click Here To see . Is it ON or OFF
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer;
//Enable SMTP debug mode
$mail->SMTPDebug = 0;
//set PHPMailer to use SMTP
$mail->isSMTP();
//set host name
$mail->Host = "smtp.gmail.com";
// set this true if SMTP host requires authentication to send mail
$mail->SMTPAuth = true;
//Provide username & password
$mail->Username = "YOUR_GMAIL_EMAIL_ID";
$mail->Password = "YOUR_GMAIL_PASSWORD";
$mail->SMTPSecure = "tls";
$mail->Port = 587;// Enter port number
$mail->ClearReplyTos();
$mail->addReplyTo("YOUR_GMAIL_EMAIL_ID", $_POST['name']); //$_POST['name'] => YOUR_GMAIL_NAME . You Can directly give "YOUR_GMAIL_NAME"
$mail->SetFrom("YOUR_GMAIL_EMAIL_ID", $_POST['name']);
$mail->addAddress($_POST["email"]); //TO WHOM U R SENDING MAIL
//Subject
$mail->isHTML(true);
$mail->Subject =" ".$_POST['subject']." ";
$body = "<html>
<head> </head>
<body>
".$_POST['message']." <br>
</body>
</html>";
$mail->MsgHTML($body);
if(!$mail->send()) {
$error_message = "Mailer Error : ". $mail->ErrorInfo;
echo $error_message;
} else {
echo "Email Sent Successfully";
}
?>

class.phpmailer.php returns SMTP connect() failed error in 000webhost.com

I use class.phpmailer.php to send a confirmation email. It works perfectly in my local server, but when I upload it to the server in 000webhost.com it no longer works.
I just discovered mail() is not working anymore either.
Is there something I can do to solve this?
Here is the code of the function I use to send every mail in my system:
code
function correoEnviar($asunto, $mensaje, $mensajeTexto, $email)
{
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxx#yahoo.com.mx'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'xxxx#yahoo.com.mx';
$mail->FromName = 'xxxx';
$mail->addAddress($email); // Name is optional
$mail->addReplyTo('xxxx#yahoo.com.mx', 'Information');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
//$mail->Subject = 'Por favor confirme su correo para obtener el libro El fractal y el =?UTF-8?Q?dise=C3=B1o=C2=A0gr=C3=A1fico?=';
$mail->Subject = $asunto;
$mail->Body = $mensaje;
$mail->AltBody = $mensajeTexto;
if(!$mail->send()) {
return $mail->ErrorInfo;
}
else
return 1;
}
echo correoEnviar($asunto, $mensaje, $mensajeTexto, "recipent#gmail.com");
?>
code
Are you sure you are including the file class.phpmailer.php, your code seems fine.
Paste the server's mailserver log, it will provide a better insight.
Your code is fine, it might be a server issue.
A sample code showing SMTP settings
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn of SMTP authentication
$mail->Username = "YAHOO ACCOUNT"; // SMTP username
$mail->Password = "YAHOO ACCOUNT PASSWORD"; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Host = "YAHOO HOST"; // SMTP host
$mail->Port = 465;

Categories