简体   繁体   中英

PHP function Mail dont work

if (@mail('email@gmail.com', 'Email Works', '$text'))) 
{
    echo('<p>Mail sent successfully.</p>');
} 
else 
{
    echo('<p>Mail could not be sent.</p>');
}

The message "Mail sent successfully" is printed but i don't receive the email

Your email content is going to be literally $text with that code.

Try

if (mail('email@gmail.com', 'Email Works', $text)) {
    echo '<p>Mail sent successfully.</p>';
} 
else {
    echo '<p>Mail could not be sent.</p>';
}

Also, Check your email and php settings to ensure you can use the mail function.

Have you setup a mail server? If not then setup one like Sendmail.

That may be possible that you have not install mail server on your server.If you are using XAMPP then Setup mail setting on XAMPP in php.ini Ex. Authentication Username, Password.

Here is link can help you to setting up smtp settings.

Try the code below

if ($mail('email@gmail.com', 'Email Works', $text)) {
    echo('<p>Mail sent successfully.</p>');
} 
else {
    echo('<p>Mail could not be sent.</p>');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM