Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Azure web app上发送PHP邮件功能?_Php_Azure_Email_Php 7_Azure Webapps - Fatal编程技术网

如何在Azure web app上发送PHP邮件功能?

如何在Azure web app上发送PHP邮件功能?,php,azure,email,php-7,azure-webapps,Php,Azure,Email,Php 7,Azure Webapps,我想使用PHP邮件函数向我的邮件发送HTML表单。 当我运行代码时,不会发生错误,但我不会收到电子邮件。 我使用了以下代码: <?php $to = 'email@email.com'; $subject = 'Subject'; $message = 'Message here'; $headers = 'From: email@email.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" .

我想使用PHP邮件函数向我的邮件发送HTML表单。 当我运行代码时,不会发生错误,但我不会收到电子邮件。 我使用了以下代码:

<?php
$to      = 'email@email.com';
$subject = 'Subject';
$message = 'Message here';
$headers = 'From: email@email.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 


我正在使用PHP 7.0在Microsoft Azure上托管我的web应用。

我尝试使用PHPmail()功能,但无法使其正常工作,因此我搜索了一些答案,结果是:

您可以在向gmail帐户或本地电子邮件服务器发送邮件时使用它

注:

当需要时,请确保PHPMailerAutoload.php的路径正确。例如:

如果要发送到本地电子邮件服务器,则必须知道主机名

您必须有一个可以用来发送邮件的帐户

分析代码是如何工作的,如有进一步的问题,请随时发表评论

我将在这里附上我开发的网站的示例代码

<?php

$strFullname = $strEmail = $strMobile = $strPosition = "";
require 'assets/api/PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer(true);

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 1;

//Ask for HTML-friendly debug output
//a$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'secure.emailsrvr.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMsTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "myemail@mailserver.com";

//Password to use for SMTP authentication
$mail->Password = "myaccountpassword";

//Set who the message is to be sent from, you can use your own mail here
$mail->setFrom('bpsourceph@gmail.com', '@noreply.bpsource.com');

//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('testmail@mailserver.com', 'Firstname Lastname');

//Set the subject line
$mail->Subject = 'New application form sent from ***** Career page';
$mail->IsHTML(true);

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
if($_SERVER["REQUEST_METHOD"]=="POST")
{
    $strFullname = $_POST['strFullname'];
    $strEmail = $_POST['strEmail'];
    $strMobile = $_POST['strMobile'];
    $strPosition = $_POST['strPosition'];
    //This part is where you will create your mail
    $mail->msgHTML("Fullname: ".$strFullname."\nEmail: ".$strEmail."\nMobile Number: ".$strMobile."\nDesired Position: ".$strPosition);


    //This part is for sending the mail
    if (!$mail->send()) {
    //If you want to check for errors. Uncomment the line below.
    //echo "Mailer Error: " . $mail->ErrorInfo;
        echo "<script>alert('Some error occured. Please try again later');</script>";
        header("Refresh:2");
}
    echo "<script>alert('Application form successfully sent!');</script>";
    header("Refresh:2");
}

?>

我想微软已经关闭了PHP邮件。(许多托管提供商都有)


微软说你应该使用SendGrid。您可以在此处阅读完整的教程:

请指定您遇到的问题以及代码的哪部分出现故障。我的收件箱中没有收到电子邮件。我没有收到任何错误,因此我猜代码没有失败?感谢您的有用回答,它现在正在工作:D@Dutch我很高兴我帮了忙:)祝你好运!谢谢你有用的回答,它现在正在工作:D
<?php

$strFullname = $strEmail = $strMobile = $strPosition = "";
require 'assets/api/PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer(true);

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 1;

//Ask for HTML-friendly debug output
//a$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'secure.emailsrvr.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMsTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "myemail@mailserver.com";

//Password to use for SMTP authentication
$mail->Password = "myaccountpassword";

//Set who the message is to be sent from, you can use your own mail here
$mail->setFrom('bpsourceph@gmail.com', '@noreply.bpsource.com');

//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('testmail@mailserver.com', 'Firstname Lastname');

//Set the subject line
$mail->Subject = 'New application form sent from ***** Career page';
$mail->IsHTML(true);

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
if($_SERVER["REQUEST_METHOD"]=="POST")
{
    $strFullname = $_POST['strFullname'];
    $strEmail = $_POST['strEmail'];
    $strMobile = $_POST['strMobile'];
    $strPosition = $_POST['strPosition'];
    //This part is where you will create your mail
    $mail->msgHTML("Fullname: ".$strFullname."\nEmail: ".$strEmail."\nMobile Number: ".$strMobile."\nDesired Position: ".$strPosition);


    //This part is for sending the mail
    if (!$mail->send()) {
    //If you want to check for errors. Uncomment the line below.
    //echo "Mailer Error: " . $mail->ErrorInfo;
        echo "<script>alert('Some error occured. Please try again later');</script>";
        header("Refresh:2");
}
    echo "<script>alert('Application form successfully sent!');</script>";
    header("Refresh:2");
}

?>