我使用的是 ubuntu 14.04。我已经使用 {sudo apt-get install postfix} 安装了 postfix。它已成功安装。现在我尝试使用终端发送邮件,我发现邮件已发送到目的地。但是当我从 /var/www/html/mailsend.php 尝试时,我发现邮件没有发送。这是我的 main.cf 代码:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#@raaj
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
#@raaj
#smtpd_banner = $myhostname ESMTP $mail_name yslserver
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = yslserver
#@raaj
#mydomain = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#akk
myhostname = yslserver
mydomain = localhost
myorigin = $mydomain
default_destination_concurrency_limit = 4
soft_bounce = yes
mydestination = $myhostname, rajkhurana, yslserver, localhost.localdomain, ,localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter =
inet_interfaces = all
inet_protocols = all
#@raaj
#mailbox_command = procmail -a "$EXTENSION"
我正在使用这个代码:
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['sendmail'])) {
//Email information
$mailFrom = "[email protected]";
$mailTo = $_REQUEST['mailto'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//print_r($_POST);
//send email
if (mail($mailTo, "$subject", $comment, "From: " . $mailFrom)){
echo "Thanks, mail has sent successfully";
}
else {
//Email response
echo "Mail could not sent..!";
}
}
//if "email" variable is not filled out, display the form
else { ?>
<html>
<head>
<style>
#main {
width:300px;
height:auto;
background-color:#D5CADA;
padding:10px;
margin:10px;
}
.section {
width:290px;
height:auto;
}
</style>
</head>
<body>
<div id="main">
<form method="post" action="">
<div class="section">
Email To: <input name="mailto" id ="mailto" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="7" cols="33"></textarea><br />
<div>
<input type="submit" name="sendmail" id="sendmail" value="Submit" />
<input type="reset" name="reset" id="reset" value="Reset"/>
</div>
</div>
</form>
</div>
</body>
</html>
<?php } ?>
请帮助我如何解决这个问题。
答案1
这听起来像是 php 问题,因为它是从命令行运行的。您是否在 php.ini 文件中定义了 sendmail 路径?