Php 如何通过我网站上的联系我们表单在我的免费gmail收件箱中获取用户邮件

Php 如何通过我网站上的联系我们表单在我的免费gmail收件箱中获取用户邮件,php,email,Php,Email,如何通过我网站上的联系我们表单在我的免费gmail收件箱中获取用户邮件。我不使用带有我网站名称的电子邮件。我使用免费的gmail。我尝试了很多脚本,但都需要域上的电子邮件帐户。基本上,它涉及PHPmail()函数: <?php mail(yourGmailAddress, object, message); ?> 正如您已经观察到的,此解决方案仅在Web服务器运行邮件服务器时有效。此邮件服务器可能禁止未知用户。因此,您需要在该web/邮件服务器上拥有一个电子邮件帐

如何通过我网站上的联系我们表单在我的免费gmail收件箱中获取用户邮件。我不使用带有我网站名称的电子邮件。我使用免费的gmail。我尝试了很多脚本,但都需要域上的电子邮件帐户。

基本上,它涉及PHP
mail()
函数:

<?php 
     mail(yourGmailAddress, object, message); 
?>


正如您已经观察到的,此解决方案仅在Web服务器运行邮件服务器时有效。此邮件服务器可能禁止未知用户。因此,您需要在该web/邮件服务器上拥有一个电子邮件帐户(我相信情况就是这样)。第二步是将邮件从您的网站地址转发到您的gmail帐户。我90%肯定这是可能的,从您的gmail配置。也可以通过您的网站邮件配置来实现。但不要同时配置这两个

基本上,它涉及PHP
mail()
函数:

<?php 
     mail(yourGmailAddress, object, message); 
?>


正如您已经观察到的,此解决方案仅在Web服务器运行邮件服务器时有效。此邮件服务器可能禁止未知用户。因此,您需要在该web/邮件服务器上拥有一个电子邮件帐户(我相信情况就是这样)。第二步是将邮件从您的网站地址转发到您的gmail帐户。我90%肯定这是可能的,从您的gmail配置。也可以通过您的网站邮件配置来实现。但不要同时配置这两个

您还可以将电子邮件地址放入表单元素的“action”属性中。但这是非常不可靠的。像这样:

<form method='post' action='mailto:your@email.com?Subject=Hello'>
...
</form>

...
用户必须安装并配置电子邮件客户端才能正常工作。还有其他一些缺点。你必须做一些研究,看看这个方法是否适合你。

您还可以将电子邮件地址放入表单元素的“操作”属性中。但这是非常不可靠的。像这样:

<form method='post' action='mailto:your@email.com?Subject=Hello'>
...
</form>

...
用户必须安装并配置电子邮件客户端才能正常工作。还有其他一些缺点。你必须做一些研究,看看这个方法是否适合你。

这个问题与此有关吗

那么,你的网站上有一个表单,你的用户填写它,你需要一封包含这些数据的电子邮件,对吗

简单的例子:

<form action="sendMail.php" method="post">
    Name: <input type="text" name="name" id="name" /><br />
    Email: <input type="text" name="email" id="email" /><br />
    Text: <textarea name="text"></textarea><br />
    <input type="submit" value="Send" />
</form>

名称:
电子邮件:
文本:
然后,发送邮件的php页面:

//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];

$from = 'your.email@gmail.com';
$to = 'your.email@gmail.com';
$gmailPass = 'your gmail password';

$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);

if(!$mail->Send()){
    echo $mail->ErrorInfo;
}else{
    echo 'sent!';
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>
//php sendThis.php页面

编辑:刚刚测试过,工作正常。确保3个文件(class.phpmailer.php、class.pop3.php和class.smtp.php)位于正确的包含路径中

这个问题与此有关吗

那么,你的网站上有一个表单,你的用户填写它,你需要一封包含这些数据的电子邮件,对吗

简单的例子:

<form action="sendMail.php" method="post">
    Name: <input type="text" name="name" id="name" /><br />
    Email: <input type="text" name="email" id="email" /><br />
    Text: <textarea name="text"></textarea><br />
    <input type="submit" value="Send" />
</form>

名称:
电子邮件:
文本:
然后,发送邮件的php页面:

//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];

$from = 'your.email@gmail.com';
$to = 'your.email@gmail.com';
$gmailPass = 'your gmail password';

$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);

if(!$mail->Send()){
    echo $mail->ErrorInfo;
}else{
    echo 'sent!';
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>
//php sendThis.php页面

编辑:刚刚测试过,工作正常。确保3个文件(class.phpmailer.php、class.pop3.php和class.smtp.php)位于正确的包含路径中

尝试启用
openssl

取消对行的注释:

extension=php_openssl.dll

在您的
php.ini
文件中。

尝试启用
openssl

取消对行的注释:

extension=php_openssl.dll

在您的
php.ini
文件中。

“我尝试了许多脚本,但都需要域上的电子邮件帐户”??您能否提供一些有关托管解决方案的信息(验证服务器?共享托管?php?仅静态HTML?)。你尝试了什么样的脚本?“我尝试了很多脚本,但都需要域上的电子邮件帐户?”?你能提供一些关于你的托管解决方案的信息吗(provate服务器?共享托管?PHP?仅静态HTML?)。你尝试了什么样的脚本?当我尝试这个时,我得到了一个错误警告:stream\u socket\u enable\u crypto()[streams.crypto]:这个流在/home/jitu/public\u html/mailer/phpMailer/class.smtp.php第194行不支持SSL/crypto,这可能是一个托管问题(限制)。我刚试过一个10欧元/年的主机,效果很好。。我用工作答案编辑我的答案。这里需要两个不同的电子邮件地址:$from='你的。email@gmail.com'; $to='你的。email@gmail.com';我现在收到此错误警告:fsockopen()[function.fsockopen]:无法连接到ssl://smtp.gmail.com:465 (找不到套接字传输“ssl”-配置PHP时是否忘记启用它?)第122行的/home/jitu/public\u html/mailer/phpMailer/class.smtp.php中smtp错误:无法尝试此操作时,我收到此错误警告:stream\u socket\u enable\u crypto()[streams.crypto]:此流在第194行的/home/jitu/public\u html/mailer/phpMailer/class.smtp.php中不支持SSL/crypto,可能是托管问题(限制)。我刚试过一个10欧元/年的主机,效果很好。。我用工作答案编辑我的答案。这里需要两个不同的电子邮件地址:$from='你的。email@gmail.com'; $to='你的。email@gmail.com';我现在收到此错误警告:fsockopen()[function.fsockopen]:无法连接到ssl://smtp.gmail.com:465 (在第122行的/home/jitu/public_html/mailer/phpMailer/class.smtp.PHP中找不到套接字传输“ssl”-配置PHP时是否忘记启用它?)smtp错误:无法