如何在php中声明全局变量以接收自定义电子邮件?
我正在做我的投资组合,在它的末尾,有一个表格(姓名、电子邮件、消息)。此表单需要向我的个人gmail帐户发送电子邮件,但我在设置全局变量时遇到了困难 表单正在运行,这是html代码如何在php中声明全局变量以接收自定义电子邮件?,php,email,global-variables,phpmailer,Php,Email,Global Variables,Phpmailer,我正在做我的投资组合,在它的末尾,有一个表格(姓名、电子邮件、消息)。此表单需要向我的个人gmail帐户发送电子邮件,但我在设置全局变量时遇到了困难 表单正在运行,这是html代码 <form action="" method="POST" id="contact-form"> <span class="contacts-text" id=&quo
<form action="" method="POST" id="contact-form">
<span class="contacts-text" id="first-contacts-text">To get in touch with me, please compile this form.</span>
<span class="contacts-text">I will reply as soon as possible. Thank you!</span>
<ul class="form-content">
<li class="form-input">
<label for="name" class="label">Full name</label>
<input class="input" id="name" type="text" name="name" required>
</li>
<li class="form-input">
<label for="email" class="label">E-mail</label>
<input class="input" id="mail" type="text" name="email" required>
</li>
<li class="form-input">
<label for="msg" class="label">Insert text</label>
<textarea class="input" id="comment" type="text" name="msg" cols="30" rows="10" style="resize: none;" required></textarea>
</li>
<li class="form-input" id="last-input">
<input class="input" id="form-button" type="submit" value="submit" name="submit" onclick="sendEmail()">
</li>
</ul>
</form>
这段代码运行良好,我正在接收电子邮件,但我需要这些变量的帮助。
提前谢谢。我解决了。我使用这个脚本“$message=$\u POST['msg']]?”,清除了函数外部的变量(在php.index的顶部);我错拼了输入lol的名称值,noob error。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->Host='smtp.gmail.com';
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='myemail@gmail.com';
$mail->Password='mypassword';
$mail->setFrom('myotheremail@gmail.com'); //i know that i have to put here a variable for client email
$mail->addAddress('myemail@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Portfolio response';
$mail->Body = ''; // here probably another variable for the content
$mail->send();
echo '';
} catch (Exception $e){
echo 'Something went wrong!'. $mail->ErrorInfo;
}