OnetSolutions
  • Home
  • ๐ŸŒWeb Hosting
    • cPanel
    • Subdomains
    • Backup
    • Webmail
      • Roundcube
    • Additional domain
    • HTTPS redirection
    • PHP email
    • PHP version
    • Softaculous
  • ๐Ÿ–ฅ๏ธVPS
    • Getting started with your VPS
    • Snapshot
    • Backup
    • Restart
    • KVM Console
    • Redirect my Domain
    • Operating System
    • Offers
    • Network
      • No Port Blocking Policy
    • Agent
    • Firewall
  • ๐Ÿ’กTutorials
    • ๐Ÿ–ฅ๏ธHow to install K3S
    • ๐ŸคHow to install Yunohost
    • ๐ŸณHow to install Docker
    • โšชHow to install Gitlab
    • ๐Ÿ“ฆHow to update the kernel
    • ๐Ÿ”‘How to change the password
    • ๐ŸงชHow to do a Speedtest
    • ๐Ÿ“…How to change the date and time
    • ๐Ÿ”—How to connect to Linux server
    • ๐Ÿ’พHow to extend a partition
    • ๐Ÿ“How to activate memory hotplug
    • โฌ†๏ธHow to upgrade Debian 11 to Debian 12
    • โฌ†๏ธHow to upgrade Ubuntu to latest version
  • ๐ŸŒDomain
    • Register
    • Incoming transfer
  • ๐Ÿ“‚Subscription
    • ๐Ÿ’ฐBilling
      • ๐Ÿ•œHow to renew?
    • ๐Ÿ•Commitment
Powered by GitBook
On this page
  • Requirements
  • Instructions

Was this helpful?

  1. Web Hosting

PHP email

PreviousHTTPS redirectionNextPHP version

Last updated 1 year ago

Was this helpful?

To bolster the security of outbound emails, we strongly advise against utilizing the PHP mail() function. This function lacks authentication, posing a vulnerability easy to exploit by harmful scripts. Consequently, we have discontinued the mail() function in our system.

We recommend using SMTP (Simple Mail Transfer Protocol) instead, as it requires authentication and provides a more secure way to send emails. With PHP, you can easily implement SMTP using popular libraries like PHPMailer. A comprehensive tutorial on setting up PHPMailer can be found at .

Requirements

  • a Web Hosting service

  • an OnetSolutions account

Instructions

To configure SMTP, you will need the following information:

  • SMTP Username: Provided in your hosting activation email, often the cPanel username.

  • SMTP Password: Also provided in your hosting activation email, often the cPanel password.

  • Email: The email address you wish to use (you can create email accounts from your cPanel).

To send emails in PHP using SMTP, you can follow these steps:

  1. Make sure you have the PHPMailer library installed in your PHP project. If not, you can download it from the official PHPMailer GitHub repository ().

  2. Include the PHPMailer library in your PHP script by adding the following line at the beginning of your code:

require 'path/to/PHPMailer/src/PHPMailer.php';
  1. Set up the SMTP configuration for your email provider. Here's an example of how to configure PHPMailer for popular email services like Gmail:

$mail = new PHPMailer\PHPMailer\PHPMailer();

// Enable SMTP debugging
$mail->SMTPDebug = 0; // Set to 2 for detailed debugging

// Set up SMTP server settings
$mail->isSMTP();
$mail->Host = '[HOST];
$mail->SMTPAuth = true;
$mail->Username = '[USERNAME]';
$mail->Password = 'your-password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Set up email content
$mail->setFrom('your-email@gmail.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->Subject = 'Subject of your email';
$mail->Body = 'Content of your email';

// Send the email
if (!$mail->send()) {
    echo 'Error sending email: ' . $mail->ErrorInfo;
} else {
    echo 'Email sent successfully!';
}

Make sure to replace 'your-email@gmail.com' and 'your-password' with your actual email credentials. Adjust the SMTP server settings, port, and security method as per your email provider's requirements.

  1. Customize the $mail object to set the sender, recipient, subject, and body of your email.

  2. Finally, call the $mail->send() method to send the email. Check the return value to handle any errors that may occur during the sending process.

By following these steps, you can send emails using PHPMailer and SMTP authentication. Remember to test your code and ensure that the email provider allows SMTP access from your hosting server.

๐ŸŒ
http://stephaneey.developpez.com/tutoriel/php/phpmailer/
https://github.com/PHPMailer/PHPMailer