繁体   English   中英

无法通过php mail()函数发送邮件

[英]Can't send mail through php mail() function

我试图通过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";
   }  
?> 

我没有收到任何错误,并且成功发送了“已发送邮件”语句,但它没有到达我的邮箱。

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM