我得到了后缀从我的服务器通过控制台使用echo "body example" | mail -s "subject example" my@email发送给我的电子邮件 echo "body example" | mail -s "subject example" my@email ,但是当我尝试从我的网站通过mail() ,PHP函数发送电子邮件,我没有收到电子邮件。 我是新来的Web服务器和邮件服务器,从我的理解,我需要postfix mts运行,以便我使用mail()函数。
我不知道为什么我的表单提交没有通过,没有什么出现在/var/log/mail.log文件中,以帮助我找出错误。 我已经检查了我的联系表单和php本身的任何错误(我从bootstrap模板中得到的,但从那以后被篡改),并且在那里找不到任何问题。
我可以使用一些帮助来find我可以采取的下一步,以找出为什么电子邮件不发送,如果有其他地方的日志,我指出潜在的错误。
为了好的措施,我已经包括我的PHP函数和forms:
<?php function send(){ if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || empty($_POST['company']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $company = $_POST['company']; // Create the email and send the message $to = 'my@email'; $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nCompany: $company\n\nPhone: $phone\n\nMessage:\n$message"; $headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; } if(isset($_POST['send'])){ send(); } ?> <!-- Some html --> <form name="sentMessage" method="post" id="contactForm" novalidate> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Name</label> <input type="text" class="form-control" placeholder="Name" name="name" id="name" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Email Address</label> <input type="email" class="form-control" placeholder="Email Address" name="email" id="email" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Phone Number</label> <input type="tel" class="form-control" placeholder="Phone Number" name="phone" id="phone" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Company</label> <input type="text" class="form-control" placeholder="Company" name="company" id="company"> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Message</label> <textarea rows="5" class="form-control" placeholder="Message" name="message" id="message" required data-validation-required-message="Please enter a message."></textarea> <p class="help-block text-danger"></p> </div> </div> <br> <div id="success"></div> <div class="row"> <div class="form-group col-xs-12"> <button type="submit" name="send" class="btn btn-default">Send</button> </div> </div> </form>
和我在/etc/postfix/main.cf postfixconfiguration文件:
smtpd_banner = ESMTP $mail_name (Ubuntu) biff = no append_dot_mydomain = no readme_directory = no 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 smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = nickborisenko.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = nickborisenko.com, ubuntu-512mb-nyc3-01, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all mydomain = nickborisenko.com smtp_generic_maps = hash:/etc/postfix/generic
编辑:这些日志是从我的apache2 / access.log:
136.167.247.240 - - [28/Mar/2016:17:35:15 -0400] "GET /contact.php HTTP/1.1" 200 2592 "http://nickborisenko.com/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" ::1 - - [28/Mar/2016:17:35:23 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.14 (internal dummy connection)" 136.167.247.240 - - [28/Mar/2016:17:35:28 -0400] "POST /mail/contact_me.php HTTP/1.1" 200 247 "http://nickborisenko.com/contact.php" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
当我尝试发送联系表单时,这些是我能find的唯一日志,而且他们似乎参与了,虽然我没有看到任何错误…
问题是我处理PHP的方式。 所有我必须解决的是将上面的函数分离到一个validation函数来validationinput,另一个实际发送表单如果validation返回true。 这个修复并不完全给我我想要的validation,但电子邮件发送,这是我唯一担心的事情。
<?php function validate(){ if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || empty($_POST['company']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; }else{ return true; } } function send(){ $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $company = $_POST['company']; // Create the email and send the message $to = 'my@email'; $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nCompany: $company\n\nPhone: $phone\n\nMessage:\n$message"; $headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; } if(isset($_POST['send'])){ send(); } ?> <form name="sentMessage" onsubmit="return validate()" method="post" id="contactForm" novalidate>