# PHPMailer Not working on Infinityfree but works offline

**URL:** <https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976>\
**Category:** Hosting Support\
**Created:** [February 12, 2020, 12:03pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976 "2020-02-12T12:03:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon96610738](https://forum.infinityfree.com/letter_avatar/anon96610738/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon96610738](https://forum.infinityfree.com/u/anon96610738)\
**Post date:** [February 12, 2020, 12:03pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976/1 "2020-02-12T12:03:48Z")

</div>

**[thecassava.co/phpmailer.php](http://thecassava.co/phpmailer.php)**

**my gmail login is failing (it shows that i might be using wrong password but my password is 100% correct as it works offline ):**  
also if i remove the `$mail->isSMTP(true);` it shows message sent successfully but i don’t recieve anything

**My code**  
\<?php  
// use PHPMailer\PHPMailer\PHPMailer;  
// use PHPMailer\PHPMailer\Exception;

```
// require 'PHPMailer/Exception.php';
// require 'PHPMailer/PHPMailer.php';
// require 'PHPMailer/SMTP.php';

date_default_timezone_set('Asia/Kolkata');

// Edit this path if PHPMailer is in a different location.
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP(true);

/*
 * Server Configuration
 */

$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "validmail@gmail.com"; // Your Gmail address.
$mail->Password = "validpassword"; // Your Gmail login password or App Specific Password.

/*
 * Message Configuration
 */

$mail->setFrom('info@thecassava.co', 'The Cassava'); // Set the sender of the message.
$mail->addAddress('vickytiwari765@gmail.com', 'John Doe'); // Set the recipient of the message.
$mail->Subject = 'PHPMailer GMail SMTP test'; // The subject of the message.
// $mail->SMTPDebug = 2;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
/*
 * Message Content - Choose simple text or HTML email
 */
 
// Choose to send either a simple text email... .
// $mail->Body = 'This is a plain-text message body'; // Set a plain text body.

// ... or send an email with HTML.
$html="<html>
                        <head>
                        <title>Cassava Team</title>
                        </head>
                        <body>
                        <h1> Welcome To Cassava </h1>
                        <p>Hi vikds,<br> We have received your query. Our representative will contact you soon.</p>
                        <p>You wrote: </p>
                        <blockquote style='background:#ddd;width:max-content; color:#2a2a2a; padding:5px; '>thisi is osme wmesage
                        </blockquote>

                        </body>
                        </html>";
$mail->msgHTML($html);
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body'; 

// Optional: attach a file
// $mail->addAttachment('images/phpmailer_mini.png');

if ($mail->send()) {
    echo "Your message was sent successfully!";
} else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

```

* * *

```
indent preformatted text by 4 spaces

```

---

<div class="post-metadata">

**Author:** ![anon96610738](https://forum.infinityfree.com/letter_avatar/anon96610738/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon96610738](https://forum.infinityfree.com/u/anon96610738)\
**Post date:** [February 12, 2020, 12:38pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976/2 "2020-02-12T12:38:24Z")

</div>

```
$mail->SMTPOptions = array(
   'ssl' => array(
     'verify_peer' => false,
     'verify_peer_name' => false,
     'allow_self_signed' => true
    )
);

```

adding the above code helped me solve this…though i’m not sure…😑

---

<div class="post-metadata">

**Author:** ![anon96610738](https://forum.infinityfree.com/letter_avatar/anon96610738/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon96610738](https://forum.infinityfree.com/u/anon96610738)\
**Post date:** [February 12, 2020, 12:42pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976/3 "2020-02-12T12:42:06Z")

</div>

now i have another issue…  
when i received the mail, in the from section it show my “[validmail@gmail.com](mailto:validmail@gmail.com)” rather than “[info@thecassava.co](mailto:info@thecassava.co)”

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [February 13, 2020, 12:27pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976/4 "2020-02-13T12:27:40Z")

</div>

> [@anon96610738](#):
>
> when i received the mail, in the from section it show my “[validmail@gmail.com](mailto:validmail@gmail.com)” rather than “[info@thecassava.co](mailto:info@thecassava.co)”

This is normal. Gmail does not allow you to send email with a sender address which is not on the account. Which effectively means you will always send with an @gmail.com address. There is no way to “fix” this, other than using a different email provider which does allow you to use your own sender address.

---

<div class="post-metadata">

**Author:** ![system](https://infinityfree-forum-uploads.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/0/b024fd3fa88bae093c9576e55c2c94e33f890206.svg) [@system](https://forum.infinityfree.com/u/system)\
**Post date:** [March 14, 2020, 12:39pm UTC](https://forum.infinityfree.com/t/phpmailer-not-working-on-infinityfree-but-works-offline/25976/5 "2020-03-14T12:39:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
