-4

我从来没有接触过任何关于用 PHP 发送电子邮件的知识。有人可以给我大纲/指导我一步一步做什么吗?

我只想知道这样做的第一步。我有谷歌,但到目前为止,他们只是提供了邮寄的代码,没有告诉把代码放在哪里,或者如何开始。

4

2 回答 2

1

It's pretty simple. Just use the mail function:

// Mail information
$to         = 'example@example.com';
$subject    = 'Subject';
$message    .= 'Content of the message.';

// Headers
$headers    = 'MIME-Version: 1.0' . "\r\n";
$headers    .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers    .= 'To: ' . $to . '<' . $to . '>' . "\r\n";
$headers    .= 'From: You <you@example.com>' . "\r\n";

// Actually send the email
mail($to, $subject, $message, $headers);

You'll need to set up a local SMTP server to send it, or your hosting should have one.

于 2013-08-19T00:46:29.153 回答
1

Look at this : PHP Mail Function

 // To
$to = 'truc@server.com';

// Subject
$subject = 'example- Test Mail';

// Message
$msg = ' - Message of mail ...';

// Headers
$headers = 'From: xxx yyyyy <mail@server.com>'."\r\n";
$headers .= 'Bcc: me <me@server.com>; him <him@server2.com>'."\r\n";
$headers .= "\r\n";

// Function mail()

mail($to, $subject, $msg, $headers);

This will work only if SMTP is configured in your web host or you will need to use gmail,yahoo or any other free SMTP server. Look at this topic Send email using the GMail SMTP server from a PHP page

于 2013-08-19T00:47:19.677 回答