Skip to content
PHP Logo

What are common pitfalls when using PHPMailer with 1&1 for sending emails via SMTP?

Common pitfalls when using PHPMailer with 1&1 for sending emails via SMTP include incorrect SMTP settings, such as using the wrong port or authentication method, and not enabling SSL or TLS encryption. To solve this issue, ensure that you have the correct SMTP settings provided by 1&1 and enable SSL or TLS encryption for secure email transmission.

php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host = 'smtp.1and1.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'your_email@example.com';
    $mail->Password = 'your_password';
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption
    $mail->Port = 587; // Use port 587 for TLS
    $mail->setFrom('your_email@example.com', 'Your Name');
    $mail->addAddress('recipient@example.com', 'Recipient Name');
    $mail->isHTML(true);
    $mail->Subject = 'Subject';
    $mail->Body = 'Email body content';

    $mail->send();
    echo 'Email sent successfully';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}