Sending emails through SMTP with PHPMailer
The error logs you are seeing point to a specific network failure rather than a logical bug in your PHP code. The core issue lies in the fputs() function failing with errno=32 and the message "SIGPIPE". In POSIX systems, this error occurs when a process attempts to write to a file descriptor that has been closed by the peer.
In the context of SMTP, this means the server is closing the connection immediately after you send a command like EHLO, HELO, or during authentication. When PHPMailer tries to write the 18-byte EHLO string and receives a broken pipe error, it interprets this as "AUTH not accepted" because the handshake was never completed. The debug output confirms this: the server rejects your initial greeting before you can even attempt to identify yourself or authenticate.
This behavior is almost exclusively caused by a mismatch between your client's transport layer security (TLS) expectations and the server's configuration. You are connecting on port 465, which is the standard for SMTPS (SMTP over SSL). On this port, an SSL/TLS handshake must occur before any SMTP protocol commands are sent. Your current code initializes a raw TCP connection and immediately attempts to send EHLO. The server sees unencrypted traffic on a port that requires encryption, drops the connection, and PHPMailer logs the SIGPIPE error.
To resolve this, you need to enable SSL/TLS in your PHPMailer configuration. In the older version of PHPMailer (v5.1) shown in your stack trace, the property is named SMTPSecure. You must set it to phpmailer://, ssl://, or tls://. Given that you are using port 465, ssl:// is the correct choice.
Here is how the configuration should look:
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.ebola.cz';
$mail->Port = 465;
$mail->Username = 'myEmail@myDomain.tld';
$mail->Password = '***CENSORED***';
// Critical fix: Enable SSL for port 465
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 2;
// Set to false in production to hide sensitive info and reduce noise
$mail->SMTPDebug = false;
When you set $mail->SMTPSecure to 'ssl', PHPMailer will automatically wrap the socket connection with SSL before sending any SMTP commands. This prevents the server from closing the pipe immediately upon receiving an unencrypted EHLO.
There is a common point of confusion regarding port 587 versus port 465. Port 587 typically uses STARTTLS, which upgrades a plain connection to encryption after the initial handshake. If your server required STARTTLS instead of direct SSL, you would need to set $mail->SMTPSecure = 'tls' and switch your $mail->Port to 587. However, since port 465 is explicitly an implicit SSL port, using 'ssl' with the existing port number is the correct approach.
Another subtle detail involves the SMTPDebug setting. In your original snippet, you set it to 2. This level of debugging prints the raw SMTP stream directly to the output, which often includes the sensitive credentials if an exception is caught and echoed. For production environments, it is best practice to disable debug output or redirect it to a log file rather than echoing it to the browser, as shown in the corrected code block above.
If you are maintaining legacy PHPMailer v5 code, be aware that newer versions (v6+) have deprecated several older properties like IsSMTP(). The modern approach relies on default behaviors and explicit SMTP instance settings, but for your current stack, enabling $mail->SMTPSecure = 'ssl' is the definitive fix for the SIGPIPE error.
For developers moving to modern PHP ecosystems, Laravel simplifies this significantly using its native mailer or packages like spatie/laravel-email. While PHPMailer remains a robust standalone solution, integrating it into a framework like Laravel often requires ensuring the service provider is correctly registered and that the underlying SMTP configuration matches the server's TLS requirements. For more details on modern email handling patterns in Laravel, you can refer to https://laravelcompany.com.
