[英]PHP dies after mail function
I'm trying to send a mail in a function and then return something afterward if succeded, but after running the mail function, which works, it seems like the PHP process just dies.我试图在一个函数中发送一封邮件,然后如果成功则返回一些东西,但是在运行邮件函数后,它的工作原理似乎是 PHP 进程终止了。
This is an example of what my code looks like right now这是我的代码现在的样子的一个例子
<?php
die(json_encode(someFunction('test@example.me')));
function someFunction($mail) {
..Some Code..
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "no-reply@example.com";
$to = $mail;
$subject = "Test";
$headers = "From: " . $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '
<h1>Test message</h1>
';
mail($to, $subject, $message, $headers);
$r->success = true;
return $r;
}
?>
And this doesn't return anything.这不会返回任何东西。
Hope you can help me.希望您能够帮助我。
Thanks in regards!谢谢你的问候!
You can't return without function.你不能没有功能就返回。 If you want to print anything just use echo or print_r.如果您想打印任何内容,只需使用 echo 或 print_r。
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
die(json_encode(someFunction('test@example.me')));
function someFunction($mail) {
$from = "no-reply@example.com";
$to = $mail;
$subject = "Test";
$headers = "From: " . $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '
<h1>Test message</h1>
';
mail($to, $subject, $message, $headers);
$r = new stdClass();
$r->success = true;
return $r;
}
?>
The error was the 2 lines错误是 2 行
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
When i removed those, the code worked当我删除它们时,代码起作用了
Thanks for trying to help with solving my problem.感谢您尝试帮助解决我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.