0

I am having a form on my HTML website and sending contact form emails via PHP functions.

Below is the code I have in php email sending file...

if( file_exists($php_email_form = '../assets/vendor/php-email-form/php-email-form.php' )) {
    include( $php_email_form );
  } else {
    die( 'Unable to load the "PHP Email Form" Library!');
  }

$mail = new PHPMailer(true);

$mail->isSMTP();// Set mailer to use SMTP
$mail->CharSet = "utf-8";// set charset to utf8
$mail->SMTPAuth = true;// Enable SMTP authentication
$mail->SMTPSecure = false;// Enable TLS encryption, `ssl` also accepted

$mail->Host = 'mail.example.com';// Specify main and backup SMTP servers
$mail->Port = 587;// TCP port to connect to
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->isHTML(true);// Set email format to HTML
 
$mail->Username = 'webmail@example.com';// SMTP username
$mail->Password = 'Password';// SMTP password

$mail->setFrom('webmail@example.com', 'WebForm Submission');//Your application NAME and EMAIL
$mail->Subject = 'Test';//Message subject




$mail->MsgHTML('HTML code');// Message body
$mail->addAddress('webmail@example.com', 'User Name');// Target email


// $mail->send();

if(!$mail->Send()) {
    echo "<p class='error'>Problem in Sending Mail.</p>";
    echo $mail->ErrorInfo;
} else {
    echo "<p class='success'>Contact Mail Sent. for sure</p>";
}

After submission, I am getting messages as

Error:
Contact Mail Sent...

can anybody help me, with why there is a success message along with the error

verma'n
  • 1
  • 2
  • 2
    Does this answer your question? [How can I send an email using PHP?](https://stackoverflow.com/questions/5335273/how-can-i-send-an-email-using-php) – Syfer Aug 26 '22 at 22:55
  • Please post the code before this, where you are instantiating the class and setting properties. – Rohit Gupta Aug 27 '22 at 05:42
  • @Syfer - He is using phpmailer (as in the tag) which has a class – Rohit Gupta Aug 27 '22 at 05:43
  • @RohitGupta I was flagging this question as duplicate. The only class I see in his code is CSS. Since those anchors can work without classes (which is purely for styling when I read the names). – Syfer Aug 28 '22 at 08:16
  • @Syfer - Well, answers their do mention phpmailer. So go for it. – Rohit Gupta Aug 28 '22 at 08:54
  • I have edited my and put my whole php calling code in here. I am just curious that when the function is executing as successful(that's why it goes into else condition), then why it contain the error along with the success message... Thanks – verma'n Aug 29 '22 at 17:23

0 Answers0