PHPMailer is a popular PHP library that makes it easier to send e‑mail messages with advanced features such as SMTP authentication, HTML formatting, and attachments. On ruachost.com, PHPMailer is supported and can be installed via Composer or Git.

 

???? Important Hosting Restrictions

  • On Shared Hosting and Reseller Hosting, you cannot use external SMTP servers.

  • You must send e‑mail through ruachost.com servers.

  • Other hosting packages (Managed VPS, Dedicated) allow external SMTP servers.

 

Installing PHPMailer

Option 1: Using Composer

Bash

composer require phpmailer/phpmailer

Option 2: Using Git

 
Bash

git clone https://github.com/PHPMailer/PHPMailer.git

Example: Sending E‑Mail with PHPMailer

<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = gethostname();   // Use ruachost.com servers for shared/reseller/WordPress hosting
$mail->SMTPAuth = true;
$mail->Username = 'sender@example.com';
$mail->Password = 'password';
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->addAddress('recipient@example.com');
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the body.';

if(!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

Features of PHPMailer

  • SMTP authentication for secure delivery.

  • HTML e‑mail support with inline images.

  • Attachments for files.

  • Error handling with detailed feedback.

 

Best Practices

  • Always set a valid From address.

  • Use SMTP authentication when available.

  • Test with different mail clients to ensure formatting.

  • Avoid sending bulk mail directly from PHP scripts; use mailing services for campaigns.

 
這篇文章有幫助嗎? 0 用戶發現這個有用 (0 投票)

Powered by WHMCompleteSolution