3

您好我需要使用 php 发送电子邮件。但是当我试图发送一封简单的电子邮件时,它没有被发送。可能是什么原因?我应该包含任何标题或任何权限吗?请帮助我。这是我的代码。

<?php
$to='jyothi.jish@gmail.com';
$message='hai';
mail($to, 'My Subject', $message);
?>

连这个小消息都没有发送。谁能猜出可能是什么原因?

4

3 回答 3

0

那么问题在于您需要在服务器中定义邮件发送参数。如邮件主机、端口等。最好使用http://phpmailer.worxware.com/。您可以使用 gmail 等第三方通过您的 localhost 开发环境为您发送邮件。

您可以使用

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; // SMTP account username example
$mail->Password   = "password";        // SMTP account password example

定义连接参数。

于 2013-11-12T06:49:02.657 回答
-1
Gmail SMTP server settings for sending mail through Gmail from any email program:

Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. example@gmail.com)
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes 

这将为您提供通过 gmail 使用 smtp 发送邮件的便利(但我还无法对其进行测试,因此您可以尝试并检查它是否适合您)。

于 2013-11-12T07:09:47.423 回答
-1

这是您可以在 Windows 中使用 PHP 从 XAMPP 或 WAMP (localhost) 发送电子邮件的方式。

a) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMPP server.
Note : Make a backup of php.ini file

b) Search [mail function] in the php.ini file.

You can find like below.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25.
Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address..

So , it will become like this.
[mail function]
; For Win32 only.
SMTP = smtp.planetghost.com
smtp_port = 25
; For Win32 only.
sendmail_from = info@planetghost.com

c) Restart the XAMPP or WAMP(apache server) so that changes will start working.

d) Now try to send the mail using the mail() function .
于 2013-11-12T06:57:37.317 回答