0

我尝试通过 php mail() 函数发送电子邮件,但无法发送邮件。我试过的代码是

<?php
    if( isset($_REQUEST['send_button']) ){
        $id = "example@example.com";
        $subject = "Sample Mail";
        $message = "This is test message";
        $headers = "From: Giridharan";
        if( mail($id, $subject, $message, $headers) === true ){ echo "mail sent"; }
    }

    if( isset($_REQUEST['staff']) ){
?>

<html>
    <body>
        <form action='send_mail.php'>
        Staff ID :<input type='text' name='to' value=<?php echo $_REQUEST['staff'];  ?> readonly style="border:none" size:30 /><br />
        Subject:<input type='text' name='subject' size:30 /><br />
        Content:<textarea name='content'></textarea><br />
        <input type='submit' name='send_button' value='Send' />
        <button type=button name='cancel_button'>Cancel</button>
        </form>
    </body>
</html>

<?php 
   }else{
        echo  " Select a staff to mail";
   }  
?> 

我没有收到任何错误,并且“已发送邮件”的声明已成功回显,但它没有到达我的邮箱。

4

1 回答 1

0

SWIFT MAILER 使流程更简单。这是工作代码

        require_once 'swift/lib/swift_required.php';
        // Create the SMTP configuration
        $transport = Swift_SmtpTransport::newInstance('mailout.one.com',25);
          $transport->setUsername('YOURMAIL@EMAIL.COM');
          $transport->setPassword('YOUR PASSWORD');

        // Create the message
        $message = Swift_Message::newInstance();
        $message->setTo(array(
           "TO_ADDRESS@EMAIL.COM"

        ));

        $message->setSubject("This is a test message ");
        $message->setBody("This is an automatically genrated message kindly do not reply.");
        $message->setFrom("YOURMAIL@EMAIL.COM", "YOUR PASSWORD");



        // Send the email
        $mailer = Swift_Mailer::newInstance($transport);
        $mailer->send($message, $failedRecipients);

        // Show failed recipients
        print_r($failedRecipients);
于 2014-03-09T07:41:35.887 回答