猿问

我在php中将电子邮件查询发送到多个电子邮件帐户时遇到问题

我在php中将电子邮件查询发送到多个电子邮件帐户时遇到问题,任何人都可以在这里帮助表单HTML版本


<form id="contact-form" action="#">

    <div class="form-field-item">

        <input type="text" required="required" name="fullname" id="fullname" size="25" placeholder="Name" class="form-field">

    </div>

    <div class="form-field-item">

        <input type="tel" id="phone" name="phone" required="required" placeholder="Contact Number" class="form-field">

    </div>

    <div class="form-field-item">

        <input type="email" required="required" name="email" id="email" placeholder="Email" class="form-field">

    </div>

    <div class="form-field-checkbox-item">

        <div class="checkbox-item">

            <input type="checkbox" id="agree-gdrp" name="agree-gdrp" required="required" value="Yes">

            <label for="agree-gdrp" class="field-label">I agree that Fraser handles my personal data in accordance with GDPR</label>

        </div>

    </div>

    <div class="form-submit-wrap">

        <button>Send Enquiry</button>

    </div>

</form>

...这是PHP:


<?php 

$recepient = "info@mail1.com,awhite@mail1.com"; 

$sitename = "Fraser"; 

$fullname = trim($_POST["fullname"]); 

$email = trim($_POST["email"]); 

$phone = trim($_POST["phone"]); 

$message = "Name: $fullname \nContact Number: $phone \nEmail: $email"; 

$pagetitle = "Fraser Contact Form"; 


mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: info@mail.com");

?>


浮云间
浏览 144回答 3
3回答

慕娘9325324

试试这个$email_to&nbsp; = "info@mail1.com,awhite@mail1.com";&nbsp;$sitename = "Fraser";&nbsp;$fullname = trim($_POST["fullname"]);&nbsp;$email = trim($_POST["email"]);&nbsp;$phone = trim($_POST["phone"]);&nbsp;$message = "Name: $fullname \nContact Number: $phone \nEmail: $email";&nbsp;$pagetitle = "Fraser Contact Form";&nbsp;mail($email_to , $pagetitle, $message);如果你的主机不阻止,它会工作,如果这样做!那么您将需要使用smtp,如gmail或其他提供商。替代你可以使用 PHPMailer

杨__羊羊

越来越多的托管商将使用mail()函数阻止发送发送给多个食谱的邮件,因为您可以提供任何由于SPF检查而被食谱阻止的“发件人”地址。您可以建立整个SMTP连接来发送邮件,也许可以使用像SwiftMailer这样的Lib。

阿波罗的战车

您如何发送要由php处理的数据。我已将脚本添加到表单操作中,并将您的提交按钮替换为提交类型的输入断续器<form id="contact-form" action="my_processing_script.php">&nbsp; &nbsp; <div class="form-field-item">&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" required="required" name="fullname" id="fullname" size="25" placeholder="Name" class="form-field">&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="form-field-item">&nbsp; &nbsp; &nbsp; &nbsp; <input type="tel" id="phone" name="phone" required="required" placeholder="Contact Number" class="form-field">&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="form-field-item">&nbsp; &nbsp; &nbsp; &nbsp; <input type="email" required="required" name="email" id="email" placeholder="Email" class="form-field">&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="form-field-checkbox-item">&nbsp; &nbsp; &nbsp; &nbsp; <div class="checkbox-item">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" id="agree-gdrp" name="agree-gdrp" required="required" value="Yes">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label for="agree-gdrp" class="field-label">I agree that Fraser handles my personal data in accordance with GDPR</label>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="form-submit-wrap">&nbsp; &nbsp; &nbsp; &nbsp; <input type='submit' value='Send Enquiry'>&nbsp; &nbsp; </div></form>my_processing_script.php<?php&nbsp;$recepient = "info@mail1.com,awhite@mail1.com";&nbsp;$sitename = "Fraser";&nbsp;$fullname = trim($_POST["fullname"]);&nbsp;$email = trim($_POST["email"]);&nbsp;$phone = trim($_POST["phone"]);&nbsp;$message = "Name: $fullname \nContact Number: $phone \nEmail: $email";&nbsp;$pagetitle = "Fraser Contact Form";&nbsp;mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: info@mail.com");?>如果您不想离开该页面,我建议您通过ajax或jquery post发布表格<button id="my-submit-button">Send Enquiry</button>JQuery$("#my-submit-button").click(function(e){&nbsp; &nbsp; var fullname = $("#fullname ").val()&nbsp; &nbsp; var phone = $("#phone ").val()&nbsp; &nbsp; var email = $("#email ").val()&nbsp; &nbsp; var agree_gdrp = $("#agree-gdrp").val()&nbsp; &nbsp; $.post("my_php_sctipt.php", {"fullname" :fullname, "phone":phone, "email" : email , "agree_gdrp": agree_gdrp }).done(function(evt){&nbsp; &nbsp; &nbsp; &nbsp; alert("data sent");&nbsp; &nbsp; })})
随时随地看视频慕课网APP
我要回答