PHP built-in mail function to SMTP class

Help me out on this please i have a site that uses a sign up and users are supposed to receive mail when someone sign up or like of the site but it wont work and i have discovered recently that its the php mail function that was disabled and i was asked to switch to SMTP and i don’t know how to, this is how the script looks:

function sendMail($to, $subject, $message, $from) {
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=utf-8’ . “\r\n”;
$headers .= ‘From: ‘.$from.’’ . “\r\n” .
'Reply-To: '.$from . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
return @mail($to, $subject, $message, $headers);

}

i really dont

I’m not sure what it is you don’t :slight_smile: but you might want to look at phpmailer

1 Like

SMTP is the native way of sending emails without using the mail function.

If you want to do it yourself you will need to use fsocketopen() to open a connection to SMTP and then send an EHLO message, then log in to the server using a valid email account and then send MAIL FROM, RCPT TO, DATA and QUIT messages. The entire email you were creating using mail() gets sent by the DATA message, the rest are the envelope that wraps the email.

If you don’t want to do it yourself then phpmailer is probably the simplest solution.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.