Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPmailer without using SMTP

Tags:

php

phpmailer

I've added the PHPMailer folder to my root folder on my web server and I just get an error that has to do with SMTP.

Is there a way to use PHPMailer without needing to log into a mail account? Can I just have the server send the email to a address?

I was searching this site and found this

$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'Your Name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( '[email protected]' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();

But I get an error that says "Message could not be sent.Mailer Error: You must provide at least one recipient email address."

like image 439
Joseph Kreifels II Avatar asked Sep 06 '15 20:09

Joseph Kreifels II


People also ask

Can I send email without SMTP server?

The simplest way to send a message is to use QuickSend method of Smtp class (this method is static, it does not require you to create an instance of Smtp class). QuickSend method allows you to send e-mails out even if you do not have an SMTP relay server.

Does PHPMailer use SMTP?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.

Can I use PHPMailer in localhost?

The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also send HTML email from localhost in PHP using PHPMailer.


1 Answers

I commented out the SMTP lines and now it works

<?php

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // 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 = '';                 // SMTP username
//$mail->Password = '';                           // SMTP password
//$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 587;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$mail->addAttachment('');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$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;
} else {
    echo 'Message has been sent';
}
?>
like image 164
Joseph Kreifels II Avatar answered Oct 07 '22 01:10

Joseph Kreifels II