# Send email through php

**URL:** https://forum.infinityfree.com/t/send-email-through-php/31040
**Category:** Hosting Support
**Created:** [June 3, 2020, 2:16pm UTC](https://forum.infinityfree.com/t/send-email-through-php/31040 "2020-06-03T14:16:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![new-user](https://forum.infinityfree.com/letter_avatar/new-user/32/5_5575768a8748004e209b776fc1b2916d.png) [@new-user](https://forum.infinityfree.com/u/new-user)
#### Post date: [June 3, 2020, 2:16pm UTC](https://forum.infinityfree.com/t/send-email-through-php/31040/1 "2020-06-03T14:16:06Z")

</div>

how can i send emails through php using infinity web hosting because it does not allow to use php mail function i am new to php so is there any other easy and secure way to send email using php i want to use it in my temp website

---

<div class="post-metadata">

### Author: ![JohnLpool](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/johnlpool/32/7024_2.png) [@JohnLpool](https://forum.infinityfree.com/u/JohnLpool)
#### Post date: [June 3, 2020, 2:42pm UTC](https://forum.infinityfree.com/t/send-email-through-php/31040/2 "2020-06-03T14:42:05Z")

</div>

you could use PHPMailer, here is an example from GitHub:

```auto
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
    $mail->isSMTP(); // Send using SMTP
    $mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'user@example.com'; // SMTP username
    $mail->Password = 'secret'; // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
    $mail->addAddress('ellen@example.com'); // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    // Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name

    // Content
    $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';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
```

Link:[github PHPMailer](https://github.com/PHPMailer/PHPMailer)

---

<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: [June 3, 2020, 4:24pm UTC](https://forum.infinityfree.com/t/send-email-through-php/31040/3 "2020-06-03T16:24:52Z")

</div>

Please check this article:

> **[How to send email with Gmail SMTP](https://forum.infinityfree.com/docs?topic=49239)**
>
> Outgoing email with PHP mail() is heavily restricted on InfinityFree. Fortunately, you can still whatever email you want using an external email service. There are many external email providers to choose from. InfinityFree doesn’t restrict sending...

---

<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: [June 18, 2020, 4:25pm UTC](https://forum.infinityfree.com/t/send-email-through-php/31040/4 "2020-06-18T16:25:03Z")

</div>

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