Skip to main content

Sending emails from 1and1 with PHPMailer

· 2 min read

In this post we are going to explain how to send emails using PHPMailer from a 1and1 server.

On the one hand, we have a config.php file where we configure the main parameters.

define('EMAIL\_CHARSET', 'UTF-8');
define('SMTP\_SERVER', '');
define('EMAIL\_USERNAME', '<your 1and1 account>');
define('EMAIL\_PASSWORD', '<your password>');
define('EMAIL\_PORT', '25');

define('EMAIL\_FROM', '<your from email>');
define('EMAIL\_FROM\_NAME', '<your from name email>');
define('EMAIL\_REPLY', '<your reply email>');
define('EMAIL\_REPLY\_NAME', '<your reply name email>');

On the other hand, here you have a sample of a php class using PHPMailer for sending emails.

require 'config.php';
require 'PHPMailer/PHPMailerAutoload.php';

class EMail {

public static function sendMail($to, $subject, $message, $message\_plain) {
$mail = new PHPMailer;

$mail->CharSet = EMAIL\_CHARSET;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP\_SERVER; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL\_USERNAME; // SMTP username
$mail->Password = EMAIL\_PASSWORD; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted

$mail->From = EMAIL\_FROM;
$mail->FromName = EMAIL\_FROM\_NAME;
$mail->addAddress($to); // Add a recipient
$mail->addReplyTo(EMAIL\_REPLY, EMAIL\_REPLY\_NAME);
// $mail->addCC('');
// $mail->addBCC('');

$mail->WordWrap = 80; // Set word wrap to 80 characters
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Port = EMAIL\_PORT;

$mail->Subject = $subject;
$mail->Body = $message;
if (!empty($message\_plain)) {
$mail->AltBody = $message\_plain;

if(!$mail->send()) {
return false;
} else {
return true;