PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 7, 2022

[FIXED] how to disable error messages in phpmailer

 July 07, 2022     debugging, forms, php, phpmailer     No comments   

Issue

I am using phpmailer for a contactform with attachment and in the php i build my own error messages. the form and email work fine but when not filling in an email address and not chosen a file to upload i got these error messages from phpmailer

Invalid address: Could not access file:

This is the code of phpmailer i use now:

// Software: PHPMailer - PHP email class                                    |
// Version: 5.1 

require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();

$mail->SMTPAuth = FALSE;
$mail->Port     = 25;  
$mail->Host     = "localhost";
$mail->Mailer   = "smtp";
$mail->SetFrom($_POST["user_email"], $_POST["user_name"]);
$mail->AddAddress("myname@myemailcom"); 
$mail->Subject = "Contactform";
$mail->WordWrap   = 80;
$mail->MsgHTML($_POST["user_message"]);

if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['user_attachment']['tmp_name'],$_FILES['user_attachment']['name']); 
}
$mail->IsHTML(true);
if(!$mail->Send()) {
    echo 'some error message';
}
else {
    echo 'success message';
}

After some research i tried to add:

$phpmailer->SMTPDebug=false; // without result

How can i get rid of these built in error messages?


Solution

First of all you're running a very old version of PHPMailer that is dangerously outdated and is exposing your site to some major vulnerabilities. Before you do anything else, upgrade. I also suggest you base your code on the current examples provided with PHPMailer.

In the code you posted, you're not enabling debug output (it's off by default) at all, so I suspect there may be other code you're not showing. You have not shown what the debug output looks like, so we can't tell whether it's really PHPMailer that's generating it.

Your PHPMailer instance is called $mail, not $phpmailer, and the SMTPDebug property is an integer, so change that line to:

$phpmailer->SMTPDebug = 0;


Answered By - Synchro
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing