通过 php 发送电子邮件并访问 php.ini

Emailing via php, and accessing php.ini

我的代码非常好(但无论如何我都会在最后包含它)但是当我使用内置的 php mail() 函数时,它 returns 是真的,我没有收到电子邮件。

我已经阅读了类似问题的其他答案,但我仍然对此感到困难,因为输出日志为空并且我无权访问(或者不知道如何访问)php.ini 文件。根据 phpinfo() 页面,它位于 /etc/php55.ini.d/php.ini 但我不知道它到底在哪里。我已经联系了我的供应商,他们没有阻止 php 发送电子邮件。

所以这是一个非常新手的问题:如何访问 php.ini 文件以便查看它是否配置正确?

PHP代码:

<?php
    session_start();
    $to = "a valid email";
    $subject = "Account Verification";
    $message = "Content removed";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From: <noreply@thefunnyzone.co.uk>' . "\r\n";
    $retval = mail ($to,$subject,$message,$header);
    if( $retval == true ){echo "Message sent successfully...";}
    else{echo "Message could not be sent...";}
?>

我建议使用 PHPMailer (https://github.com/Synchro/PHPMailer)。它更易于使用,并且是使用 PHP 发送电子邮件的标准。访问 github 页面并查看 class 功能以了解更多信息。 下面是一个例子。

require_once("./inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();

if (!isset($error_message)) {
    $email_body = "";
    $email_body = $email_body . "Name: " . $name . "<br>";
    $email_body = $email_body . "Email: " . $email . "<br>";
    $email_body = $email_body . "Message: " . $message;

    $mail->SetFrom($email, $name);
    $mail->AddAddress($address, "Joe User");
    $mail->Subject    = $subject . $name;
    $mail->MsgHTML($email_body); 

    // if the email is sent successfully, redirect to a thank you page;
    // otherwise, set a new error message
    if($mail->Send()) {
      //set success message
    } else {
      //set error meesage        }

}