除非绝对必要,否则我会建议使用一个很好的老式变量来完成这个特定的任务,而不是一个常量。
如果你想用一个常数:
define('MAIL_TO', '[email protected]');
define('MAIL_FROM', '[email protected]');
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: " . MAIL_FROM . "\r\nReply-To: [email protected]";
$mailResult = mail(MAIL_TO, $subject, $message, $headers);
FYI:
// Constants can also be retrieved with the constant() function
$mailTo = constant('MAIL_TO');
// ...which is the same as...
$mailTo = MAIL_TO;
随着使用常量:
$mailTo = '[email protected]';
$mailFrom = '[email protected]';
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: " . $mailFrom . "\r\nReply-To: [email protected]";
$mailResult = mail($mailTo, $subject, $message, $headers);
你为什么要使用定义为'到'和'从'地址? – GWW
你的问题有点含糊。 “定义”是什么意思?你想让人们填写一个表格并让PHP检索这些值吗? –
知道如何做到这一点。 – work