Sending E‑Mail Using PHPMailer
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
Section titled “???? 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
Section titled “Installing PHPMailer”Option 1: Using Composer
Section titled “Option 1: Using Composer”composer require phpmailer/phpmailerOption 2: Using Git
Section titled “Option 2: Using Git”git clone https://github.com/PHPMailer/PHPMailer.gitExample: Sending E‑Mail with PHPMailer
Section titled “Example: Sending E‑Mail with PHPMailer”<?phpuse 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
Section titled “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
Section titled “Best Practices”- Always set a valid
Fromaddress. - 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.