How to enable mail() in PHP - Alibaba Cloud Developer Forums: Cloud Discussion Forums

Unity
Intern
Intern
  • UID4463
  • Fans0
  • Follows0
  • Posts3
Reads:1349Replies:7

How to enable mail() in PHP

Created#
More Posted time:Nov 24, 2017 18:18 PM
Hi I set up WordPress on my Web Hosting server and I am seeing the error message whenever the form tries to send an email:


"Call to undefined function mail()"


How do I enable PHP mail() function? I checked phpinfo() and it looks like mail has been disabled.


Thanks

shhanshan
Forum Moderator
Forum Moderator
  • UID105
  • Fans5
  • Follows0
  • Posts343
1st Reply#
Posted time:Nov 25, 2017 19:37 PM
Hi Unity,
mail() function is not supported in web hosting.
Regards
AlibabaCloud.com

Unity
Intern
Intern
  • UID4463
  • Fans0
  • Follows0
  • Posts3
2nd Reply#
Posted time:Nov 28, 2017 2:03 AM
Thanks. How do we send e-mails from the Wordpress form then?

Unity
Intern
Intern
  • UID4463
  • Fans0
  • Follows0
  • Posts3
3rd Reply#
Posted time:Dec 1, 2017 7:13 AM
Wordpress uses mail() in the wp_mail() function to send emails telling us about submissions to our form

shhanshan
Forum Moderator
Forum Moderator
  • UID105
  • Fans5
  • Follows0
  • Posts343
4Floor#
Posted time:Dec 5, 2017 2:14 AM
AlibabaCloud.com

BrianBae
Assistant Engineer
Assistant Engineer
  • UID5909
  • Fans0
  • Follows0
  • Posts54
5Floor#
Posted time:Jul 10, 2018 2:07 AM
just check with this script.

<?php
if ( function_exists( 'mail' ) )
{
    echo 'mail() is available';
}
else
{
    echo 'mail() has been disabled';
}
?>

GhulamQadir
Engineer
Engineer
  • UID5968
  • Fans2
  • Follows0
  • Posts63
6Floor#
Posted time:Jul 22, 2018 4:59 AM
wp_mail() is defined in wp-includes/pluggable.php. This file is loaded after the plugins are loaded, but before the hook plugins_loaded has been fired.
So the answer is: wait.


add_action( 'plugins_loaded', 'renderHTML' );
On a side note: prefix your function names and your global variables.

BrianBae
Assistant Engineer
Assistant Engineer
  • UID5909
  • Fans0
  • Follows0
  • Posts54
7Floor#
Posted time:Jul 23, 2018 15:10 PM
You can use phpsmtp library

https://code.google.com/a/apache-extras.org/p/phpmailer/

<?php

function sendMail($EMAIL, $NAME, $SUBJECT, $CONTENT, $MAILTO, $MAILTONAME){
    $mail             = new PHPMailer();
    $body             = $CONTENT;
 
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "www.coolio.so"; // SMTP server
    $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                               // 1 = errors and messages
                                               // 2 = messages only
    $mail->CharSet    = "utf-8";
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "XXXXX";             // GMAIL username
    $mail->Password   = "XXXX";              // GMAIL password
 
    $mail->SetFrom($EMAIL, $NAME);
 
    $mail->AddReplyTo($EMAIL, $NAME);
 
    $mail->Subject    = $SUBJECT;
 
    $mail->MsgHTML($body);
 
    $address = $MAILTO;
    $mail->AddAddress($address, $MAILTONAME);
 
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }
}
?>






<?php
sendMail("test@abc.com", "test mail", "Hi all.", "abc@gmail.com", "user);
?>
Guest