0

我几乎尝试了一切。我只想发电子邮件。

我的第一个代码:

<?php
$to = "yourgmail@gmail.com";
$subject = "HELLO";
$body = "HI!";
try {
    mail($to, $subject, $body);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
?>

它不工作。没有错误信息,不工作。

我的第二个代码:

function send_mail('mygmail@gmail.com','yourgmail@gmail.com','HELLO','HI!')
{
    $headers = '';
    $headers .= "From: $from\n";
    $headers .= "Reply-to: $from\n";
    $headers .= "Return-Path: $from\n";
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Date: " . date('r', time()) . "\n";

    mail($to,$subject,$body,$headers);
}

它也不起作用。

请帮我 :)

4

1 回答 1

0

这行得通吗?

第一部分:

<?php 

$to = "yourgmail@gmail.com"; 
$subject = "HELLO"; 
$body = "HI!"; 
$from = "mygmail@gmail.com";

send_mail($to,$from,$subject,$body);

?>

第二部分:

<?php

function send_mail($to,$from,$subject,$body) { 

  $headers = ''; 
  $headers .= "From: $from\n"; 
  $headers .= "Reply-to: $from\n"; 
  $headers .= "Return-Path: $from\n"; 
  $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n"; 
  $headers .= "MIME-Version: 1.0\n"; $headers .= "Date: " . date('r', time()) . "\n";

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

}

?>

我不确定你是否可以使用 php 邮件功能通过你的 gmail 发送邮件,从来没有调查过,这应该适用于 name@yourdomain.com

于 2013-08-14T04:49:01.337 回答