我们可以在1页中包含2个Mail()函数吗?

时间:2014-12-31 11:07:01

标签: php email mysqli

我想在2个不同的人发送2个不同的电子邮件发送消息'按钮。我对此几乎没有任何疑问。

  1. 是否可以从同一页面发送多封电子邮件。

  2. 我编写了以下代码,但它没有发送任何电子邮件并返回错误消息。

    <?php
    
    include 'connect.php';
    
    $subject = $_REQUEST['subject'] ; // Subject of your email
    $personal_email= "abc@hotmail.com";
    
    
    $message .= 'Name: ' . $_REQUEST['name'] . "<br>";
    $message .= $_REQUEST['product_type']. "<br>";
    $message .= $_REQUEST['message'];
    
    
    $subject_to_sender= "Confirmation";
    $message_to_sender = "Thanks for contacting us, Our representative will contact you shortly.";
    
    
    
    $name=            mysql_real_escape_string($_REQUEST['name']);
    $email=           mysql_real_escape_string($_REQUEST['email']);
    $message=     mysql_real_escape_string($_REQUEST['message']);
    $product_type=    mysql_real_escape_string($_REQUEST['product_type']);
    $address=     mysql_real_escape_string($_REQUEST['address']);
    
    if($address== "")
    {
      $address= "No Address is given.";
    }
    
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    
    
    if (@mail($email, $subject_to_sender, $message_to_sender, $headers))
    {
      mail($personal_email, $subject, $message, $headers);
      // Transfer the value 'sent' to ajax function for showing success message.
      echo 'sent';
    

1 个答案:

答案 0 :(得分:1)

要回答您以前的问题,我可以说是的,可以多次使用mail()功能。

对于后面的问题,最后if()语句的左括号未关闭。在}声明之后添加echo 'sent';