Skip to content

A PHP email sending implementation using PHPMailer library version 5.2.4. This implementation provides a robust way to send emails through SMTP with support for HTML content, attachments, and various security features. Sending mail with smtp and webmail in PHP / PHP Mailer Class.

License

Notifications You must be signed in to change notification settings

oxcakmak/PHP-smtp-webmail-PHP-Mailer-Class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

PHP-smtp-webmail-PHP-Mailer-Class

A PHP email sending implementation using PHPMailer library version 5.2.4. This implementation provides a robust way to send emails through SMTP with support for HTML content, attachments, and various security features. Sending mail with smtp and webmail in PHP / PHP Mailer Class.

Support Me

This software is developed during my free time and I will be glad if somebody will support me.

Everyone's time should be valuable, so please consider donating.

https://buymeacoffee.com/oxcakmak

Table of Contents

Features

  • SMTP email sending
  • HTML and plain text email support
  • File attachments support
  • CC and BCC recipients
  • DKIM signing capability
  • Multiple character set support
  • Error handling and debugging
  • Custom headers support
  • Embedded images in HTML
  • VERP support
  • Multiple protocols (mail, sendmail, smtp)

Requirements

  • PHP 5.0 or higher
  • SMTP server access
  • SSL/TLS support for secure connections
  • Required PHP extensions:
    • openssl
    • pdo
    • mbstring

Basic Usage

require_once __DIR__ . '/smtpmailer.php';

$mail = new SmtpMailer();

// Configure SMTP settings
$mail->IsSMTP();
$mail->Host = 'your.smtp.server';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // or 'tls'
$mail->Port = 465; // or 587 for TLS
$mail->Username = 'your_username';
$mail->Password = 'your_password';
$mail->CharSet = 'utf-8';

// Set email content
$mail->IsHTML(true);
$mail->From = 'sender@example.com';
$mail->FromName = 'Sender Name';
$mail->AddAddress('recipient@example.com');
$mail->Subject = 'Email Subject';
$mail->Body = 'HTML message body';
// not necessary actually
$mail->AltBody = 'Plain text message body';

// Send email
if($mail->Send()) {
    echo "Email sent successfully";
} else {
    echo "Email sending failed: " . $mail->ErrorInfo;
}

Advanced Features

Adding Attachments

$mail->AddAttachment('path/to/file.pdf', 'filename.pdf');

Adding CC and BCC

$mail->AddCC('cc@example.com');
$mail->AddBCC('bcc@example.com');

Adding Embedded Images

$mail->AddEmbeddedImage('path/to/image.jpg', 'image_cid');
$mail->Body = 'Embedded image: <img src="cid:image_cid">';

DKIM Signing

$mail->DKIM_domain = 'example.com';
$mail->DKIM_private = 'path/to/private.key';
$mail->DKIM_selector = 'selector';
$mail->DKIM_passphrase = '';

Error Handling

The library includes comprehensive error handling:

try {
    if(!$mail->Send()) {
        echo "Error: " . $mail->ErrorInfo;
    }
} catch (phpmailerException $e) {
    echo "Error: " . $e->errorMessage();
}

Debugging

Enable debugging for troubleshooting:

$mail->SMTPDebug = 1; // 0 = off, 1 = client messages, 2 = client and server messages

Security Considerations

  • Always use SMTPSecure with SSL/TLS when possible
  • Keep credentials secure and never commit them to version control
  • Validate email addresses before sending
  • Use appropriate error handling
  • Keep PHPMailer updated to the latest version
  • Implement rate limiting if sending bulk emails

Known Limitations

  • Some features require PHP 5.3 or higher
  • SMTP connections might be blocked by firewalls
  • File attachment size limitations based on PHP settings
  • Some email clients might handle HTML emails differently

Troubleshooting

Common issues and solutions:

  1. Connection failed

    • Check SMTP credentials
    • Verify port numbers
    • Ensure SSL/TLS settings match server requirements
  2. Authentication failed

    • Verify username and password
    • Check if SMTP authentication is required
  3. Timeout issues

    • Adjust SMTP timeout settings
    • Check server response time

License

This implementation uses PHPMailer which is distributed under the LGPL license.

Credits

Based on PHPMailer:

About

A PHP email sending implementation using PHPMailer library version 5.2.4. This implementation provides a robust way to send emails through SMTP with support for HTML content, attachments, and various security features. Sending mail with smtp and webmail in PHP / PHP Mailer Class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages