首页 > 解决方案 > sendmail 在 localhost 中有效,但在 heroku 中无效

问题描述

sendmail 在本地工作,但我不确定为什么它不能在 Heroku 上工作。应用程序日志附在下面。

发送邮件程序:

<section class="container grey-text">
<h4 class="center">2-Step Verification</h4>
<script defer src= "2-StepScript.js"></script> <!--javascript script for 2-step verification page-->

<?php
$code = "";
function generateKey() //generates the key to be sent to user
{
    $keyLength = 8;
    $characters = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $randomStr = substr(str_shuffle($characters), 0, $keyLength);
    return $randomStr;
}

function sendEmail() //send email to user
{
    $to_email = $_SESSION['email'];
    $subject = "2-Step Verification";
    $message = "Hi " . $_SESSION['firstName'] . ".\n\nThis is your 2-step verification number: ";
    $header = "From: OCCSS";
    $sCode = generateKey();
    $body = $message . $sCode;
    
    if (mail($to_email, $subject, $body, $header)) 
    {
        echo "Email successfully sent to $to_email...";
    } 
    else 
    {
        echo "Email sending failed...";
    }
    return $sCode;
}

Heroku 上的应用程序日志

标签: phpherokusendmail

解决方案


推荐阅读