简体   繁体   中英

Unable to send mail from php application in ubuntu server

Recently I moved a PHP application from a linux server to a linux Ubuntu 3.6 server and the version of PHP in the

old server = 5.4
ubuntu 3.6 = 5.3.6-13

but now the mail application is not working in ubuntu server but below command returns true:

if(mail('abc@xyz.com', 'test-subject', 'test-text-blablabla'))
   echo 'ok';
else
   echo 'bad';

I came to know while googling that we need to make changes in some php.ini file but I dont no where exactly I need to make changes.

Can any one help me out to solve little question please ?

Just a quick view of your mail function, you are missing the "from" field no? My personal thoughts would be to use something like PHPMailer or SwiftMail and see if you can use an SMTP server too (not required to use SMTP server though). They provide an error response which would defo help you.

Refer to the PHP Mail() link on php.net and create some headers as the example below shows:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

您是否配置了新服务器,以便通过安装诸如nullmailer,sendmail或其他软件包来将电子邮件重定向到实际的smtp服务器?

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