简体   繁体   English

从本地主机发送电子邮件到Gmail

[英]Send email from localhost to Gmail

I am new to PHP & want to we send email from localhost to my gmail address. 我是PHP新手,希望我们将电子邮件从本地主机发送到我的Gmail地址。

I am using ubuntu 9.10 & have already installed libphp-phpmailer from Synaptic Package manager option. 我正在使用ubuntu 9.10,并且已经从Synaptic软件包管理器选项安装了libphp-phpmailer。

I used: 我用了:

$to      = "abc@gmail.com";
$subject = "Account Confirmation";
$headers = "From: xyz@gmail.com";
$message = "Testing";
$mail = mail($to, $subject, $message, $headers);

if ($mail) {
    echo "Mail sent.";
} else {
   echo "Some Error occur.";
}

And it show Some Error occur. 并且它显示某些错误发生。

I'm using sendmail services to intall 我正在使用sendmail服务进行安装

apt-get install sendmail apt-get install sendmail

It makes your computer to be mail server and you can send wherever you want with domain that you want... 它使您的计算机成为邮件服务器,您可以使用自己想要的域将其发送到任何地方。

Welcome to SO. 欢迎来到SO。

assume under "localhost" you mean "windows". 假设“本地主机”下的意思是“ Windows”。
you will need either to install your own mail server or to use some SMTP class, like PHPMailer , to send mail using your IPS's server 您将需要安装自己的邮件服务器或使用某些SMTP类(例如PHPMailer )来使用IPS服务器发送邮件

You don't need PHPMailer (thus the libphp-phpmailer package) to use the mail() function (also, I would recommend swiftmailer over PHPMailer anytime). 您不需要PHPMailer(因此为libphp-phpmailer软件包)即可使用mail()函数(此外,我建议您始终建议通过PHPMailer使用swiftmailer )。 Also, if you want to use the mail() function you will need a Mail Transport Agent ( MTA ). 另外,如果要使用mail()函数,则需要一个邮件传输代理( MTA )。 I recommend installing the postfix package (it's available by default in Ubuntu, just use sudo apt-get install postfix ). 我建议安装postfix软件包(默认情况下在Ubuntu中可用,只需使用sudo apt-get install postfix )。 After that, your code should output Mail sent. 之后,您的代码应输出已Mail sent. :) :)

-1 to the other two answers for not reading your question. -1对其他两个答案未读您的问题。

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

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