所以我从头开始建立自己的网站,我想创建一个电子邮件功能。现在我想做到这一点,以便用户不必使用Outlook或其他任何东西向我发送电子邮件,我想要它,以便他们可以通过点击按钮发送给我。
现在这基本上是我现在使用的要点
mail($to, $subject, $body);
然而,这只有在我将我的电子邮件设置为我的托管服务器电子邮件(byethost)时才有效。我尝试将其设置为我的Gmail帐户,但这没有用。
那么,我该怎么办才能让它向我的Gmail发送电子邮件
答案 0 :(得分:0)
您需要SMTP才能使用Gmail发送邮件。 PHPMailer是我一直用来做这件事的人。
答案 1 :(得分:0)
您说您在托管服务器电子邮件(byethost)中收到邮件,但未在Gmail帐户中收到邮件。但你应该在Gmail中获取邮件。你会检查你的垃圾邮件文件夹吗?如果您使用正确的电子邮件标题发送邮件,则应将其放入收件箱。 check here complete-mail-header
为避免服务器配置问题,您可以使用PHP mailer。您还可以使用此
配置IMAP和POP3答案 2 :(得分:0)
我在其中一个项目中有类似的情况,其中用户的(网站访问者)查询将被发送到网站管理员(gmail帐户)。用Ajax调用发送了表单上收集的详细信息,发布到使用Postfix发送邮件的php文件。 (该网站托管在Ubuntu服务器上)。
页面中的JQuery代码如下所示。
$email=$_POST['email'];
$subject = 'New Query';
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$message = $_POST['msg']. "\r\n" .$_POST['query'] . "\r\n\r\nEmail : " . $email ;
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
$send_mail = mail("mycontact@gmail.com", $subject, $message, $headers);
if(!$send_mail)
{
//If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}else{
$output = json_encode(array('type'=>'message', 'text' => 'Hi, We have added '.$user_email .' to the query. Will answer you soon. Thank you for your interest.'));
die($output);
}
}
以
处理请求的PHP代码angular.module("powerpotApp", [])
.controller('mainCtrl', function($scope, dataService) {
dataService.getPlants(function(response) {
$scope.plants = response.data;
});
});
.service('dataService', function($http) {
this.getPlants = function(callback) {
$http.get('mock/plants.json').then(callback)
}
});
答案 3 :(得分:0)
如果它只是为了好玩,你可以考虑使用一个选项是使用Sengrid,它非常简单有效。在byethost中,email()函数不起作用。 获得APIKEY后,您可以轻松设置电子邮件。这是来自github的PHP的代码:
$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
$email = new SendGrid\Email();
$email
->addTo('foo@bar.com')
->setFrom('me@bar.com')
->setSubject('Subject goes here')
->setText('Hello World!')
->setHtml('<strong>Hello World!</strong>')
;
$sendgrid->send($email);
// Or catch the error
try {
$sendgrid->send($email);
} catch(\SendGrid\Exception $e) {
echo $e->getCode();
foreach($e->getErrors() as $er) {
echo $er;
}
}
你有一个免费的计划,每月有足够的免费电子邮件。