Why is PHP mail() function not working?

To combat email spam, Web4Africa restricts the use of our server for mass mailing. You must use SMTP authentication method in your PHP code. Kindly edit your code or refer to your PHP developer.

Note about using SMTP with PHP:

You need to create an email account to be used in sending emails, through your hosting control panel.
Enter the following settings in your script:

SMTP Server: your domain name
SMTP Port: 465
SMTP Username: email address you created
SMTP Password: the password of the email account you created

Sending Mail from PHP Using SMTP Authentication and SSL Encryption

A sample PHP code is shared below:

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

Most Content Management Systems like WordPress or Drupal as well as e-commerce web software like OpenCart allow the configuration of SMTP. Where this is not supposed natively, plugins are usually available to enable support for PHP SMTP.

It is also a very good idea to enable CAPTCHAs on all your web forms.

Was this article helpful?

Related Articles

Leave A Comment?

This site uses Akismet to reduce spam. Learn how your comment data is processed.