Home > Software design >  Phpmailer sending email as plain text to emails
Phpmailer sending email as plain text to emails

Time:01-27

O am for the first time facing an issue with phpmailer, does anyone has any idea why phpmailer is sending email as follow? it somehow not tonverting the email into html contecn i just cannot seem to figure out why this is happening

[email protected]
6:16 PM (0 minutes ago)
to me

--b1_948b9a2ff8436cf0db01abf3e30c0373
Content-Type: text/plain; charset=us-ascii


Request information form was submitted, details are given below.




                        Name
                        Email
                        Mobile
                        State
                        Plans
                        Destination
                        Total Travellers
                        Travel Within
                        Comments


                        debojit
                        [email protected]
                        451-245-7845
                        Georgia
                        Bags packed, I'm ready to go!
                        France
                        9 people
                        6-9 months
                        werwer




Regards,

company name



--b1_948b9a2ff8436cf0db01abf3e30c0373
Content-Type: text/html; charset=us-ascii


<h4>Request information form was submitted, details are given below.</h4>
<br/>
        <table border="1" style="width:100%">
        <tbody>
                <tr>
                        <td><b>Name</b></td>
                        <td><b>Email</b></td>
                        <td><b>Mobile</b></td>
                        <td><b>State</b></td>
                        <td><b>Plans</b></td>
                        <td><b>Destination</b></td>
                        <td><b>Total Travellers</b></td>
                        <td><b>Travel Within</b></td>
                        <td><b>Comments</b></td>
                </tr>
                <tr>
                        <td>debojit</td>
                        <td>[email protected]</td>
                        <td>451-245-7845</td>
                        <td>Georgia</td>
                        <td>Bags packed, I'm ready to go!</td>
                        <td>France</td>
                        <td>9 people</td>
                        <td>6-9 months</td>
                        <td>werwer</td>
                </tr>
        </tbody>
</table>               
<br/><br/>
Regards,
<br/>
company name



--b1_948b9a2ff8436cf0db01abf3e30c0373--

this is how i send mails

$mail = new Mail();
$mail->setFrom(senderemail);
$mail->addAddress(email);
$mail->addReplyTo($email);
$mail->subject($subject);
$mail->body($body);
//$mail->send();      
if($mail->send()){
     echo '<div  role="alert">Thanks for contacting us, we\'ll get back to you soon.</div>';
     echo "<meta http-equiv='refresh' content='5;url=contact-us.php'>";

    }else{
     echo '<div  role="alert">Some problem occurred, please <a href="contact-us.php">try again</a>.</div>';
    echo "<meta http-equiv='refresh' content='5;url=contact-us.php'>";
  }
}   

I tried adding $mail->IsHTML(true); etc but nothing seems to be working, what could be possible wrong here guys?

CodePudding user response:

This is complete fabrication that bears only minor resemblance to valid PHPMailer code – it's not even valid PHP! Unless you're using a wrapper/subclass that you have not told us about?

$mail = new Mail();
$mail->setFrom(senderemail);
$mail->addAddress(email);
$mail->addReplyTo($email);
$mail->subject($subject);
$mail->body($body);

The PHPMailer class is called PHPMailer, not Mail. The subject is set using the Subject property; there is no such method as subject(). Similarly, there is no such method as body(); to set the body set the Body property. Overall it should be:

$mail = new PHPMailer();
$mail->setFrom($senderemail);
$mail->addAddress($email);
$mail->addReplyTo($email);
$mail->Subject = $subject;
$mail->Body = $body;

PHPMailer does not do any HTML conversion. It's entirely up to you to create the HTML that you will send as part of the message body, and you also have to tell it you're using HTML, like:

$mail->isHTML();
$mail->Body = '<h1>Lovely HTML</h1>';
$mail->AltBody 'boring plain text';

All the docs and examples show you this, so perhaps you should give them a read.

CodePudding user response:

The issue was solved by enabling smtp login details

  •  Tags:  
  • Related