简体   繁体   English

使用 smtp 通过 PHPMailer 发送 Email 例如提交报价

[英]Send Email via PHPMailer with smtp e.g. submitting a quote

I need to write a code where user fills a form / submit Quote to a website.我需要编写一个代码,用户填写表格/向网站提交报价。 As user submit Quote website owner should recieve an email.当用户提交报价时,网站所有者应收到 email。 I used PHPMailer set smtp Host to smtp.gmail.com and sending email from user to owner. I used PHPMailer set smtp Host to smtp.gmail.com and sending email from user to owner. It works perfectly fine.它工作得很好。 But where I have to put password, I am quite confused, that username is the email I get from form but I am not getting any password of sender/user's email.但是在我必须输入密码的地方,我很困惑,该用户名是我从表单中获得的 email,但我没有收到发件人/用户 email 的任何密码。 Without putting password in the code I am unable to send email from user.如果没有在代码中输入密码,我将无法从用户那里发送 email。 What changes Do I need in my following code to submite Quote properly.我需要在以下代码中进行哪些更改才能正确提交报价。 Kindly Guide me.请指导我。 Here is my code:这是我的代码:

<form action="submitQuote.php" method="post" id="submit-quote">
            <input type="text" name="name" placeholder="NAME" required>
            <input type="email" name="email" placeholder="EMAIL" required>
            <input type="tel" name="phone" placeholder="PHONE" required>
            <div class="select-box">
                <select name="service" id="services">
                <option value="select service">SERVICE</option>
                <option value="Branding">Branding</option>
                <option value="Signage">Signage</option>
                <option value="Printing">Printing</option>
                <option value="Exhibition">Exhibition</option>
                <option value="Interiors">Interiors</option>
            </select>
                <span class="dropdown-icon">⌄</span>
            </div>
            <div class="select-box">
                <select name="budget" id="budget">
                <option value="select budget">BUDGET</option>
                <option value="5,000 AED - 10,000 AED">5,000 AED - 10,000 AED</option>
                <option value="11,000 AED - 20,000 AED">11,000 AED - 20,000 AED</option>
                <option value="21,000 AED - 30,000 AED">21,000 AED - 30,000 AED</option>
                <option value="31,000 AED - 40,000 AED">31,000 AED - 40,000 AED</option>
                <option value="41,000 AED - 50,000 AED">41,000 AED - 50,000 AED</option>
                <option value="61,000 AED - 80,000 AED">61,000 AED - 80,000 AED</option>
                <option value="81,000 AED - 1,00,000+ AED">81,000 AED - 1,00,000+ AED</option>
            </select>
                <span class="dropdown-icon">⌄</span>
            </div>
            <input type="submit" name="submit" value="SUBMIT">
        </form>


//PHP Code

<?php 

//Send Quote
require "mail/PHPMailer.php";
require "mail/SMTP.php";
require "mail/Exception.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

if(isset($_POST['submit'])){
//Get User Data from form

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$budget = $_POST['budget'];

$subject = "Test Mail";
$headers = "From :" . $email;
$message = $name . " " . $phone . " " . $budget . " " . $service;

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = $email; // Sender's Email got from form value
$mail->Password = ""; //what should be there
$mail->Subject = $subject;
$mail->Body = $message;
$mail->setFrom("websiteowner@concav.com");
$mail->addAddress("websiteowner@concav.com");
$mail->isHTML(true);

if ($mail->send())
{
    echo "Message accepted <br>";
}
else
{
    echo "Error: Message not accepted <br>";
}
$mail->smtpClose();

}
?>

$mail->Username = "your-email@gmail.com"; $mail->用户名 = "你的邮箱@gmail.com"; //your email address from GMAIL //你的email地址来自GMAIL

$mail->SetFrom("from-email@xyz.com", "from-name"); $mail->SetFrom("from-email@xyz.com", "from-name"); // the email sent by user via form post. // 用户通过表单发送的 email。

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

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