Effect of using PHP mail()

淺唱寂寞╮ 提交于 2019-12-13 07:08:58

问题


I've got a project where by I send email using PHP's inbuilt mail() function, I'm only sending one email at a time with a small amount of HTML and very limited CSS (two tables and a little CSS in the head for styling), but the server seems to be doing it really slowly (so much so that the page upon which an admin sends the email frequently times out)

So my question is this; does mail() put a high workload on the server (not sure if that is the right term) or is it just that the server I'm using is rubbish?

Is it worth me looking into projects like http://pear.php.net/package/Mail for this kind of thing?

EDIT:

Here is the code in question:

    $query = "SELECT email FROM $a_table WHERE id='$Id'";
    $result = mysql_query($query) or die("Query failed: ".mysql_error());

    $mail_to = mysql_fetch_row($result); 
    $mail_to = $mail_to[0];

    // multiple recipients
    $to  = $mail_to;
    // subject
    $subject = 'notification';

    // message
    $message = '<html>
    <head>
      <title>title goes here</title>
      <style type="text/css">
        table { border: 1px solid #000;}
        table tr th { background-color: #d8d8d8; border-bottom: 1px solid #000}
        table tr th, table tr td { padding: 4px; text-align: center; }
      </style>
    </head>
    <body>
          <h1>header goes here</h1>
          <table cellspacing="0">
            <tr>
              <th>th1</th><td>'.$var.'</td>
            </tr>
            <tr>
              <th>th2</th><td>'.$var2.'</td>
            </tr>
            <tr>
              <th>th3</th><td>'.$var3.'</td>
            </tr>
          </table>

          <p>&nbsp;</p>

          <table cellspacing="0">
            <tr>
                <th colspan="13">Key</th>
            </tr>
            <tr>
                <th>G</th>
                <th>I</th>
                <th>L</th>
                <th>M</th>
                <th>N</th>
                <th>O</th>
                <th>Q</th>
                <th>R</th>
                <th>S</th>
                <th>V</th>
                <th>W</th>
                <th>C</th>
                <th>?</th>
            </tr>
            <tr>
                <td>G</td>
                <td>I</td>
                <td>L</td>
                <td>M</td>
                <td>U</td>
                <td>O</td>
                <td>Q</td>
                <td>R</td>
                <td>S</td>
                <td>V</td>
                <td>W</td>
                <td>C</td>
                <td>R</td>
            </tr>
        </table>
    </body>
    </html>


    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


    // Additional headers
    $headers .= 'From: admin<admin@admin.com>' . "\r\n"; // might need to get rid of this soon

    // Mail it
    mail($to, $subject, $message, $headers);
    }

回答1:


The mail() function is usually very fast. I've used it in the past for mass email systems and that was processing hundreds of emails per second.

I'd recommend checking how your system is configured to send email. mail() generally utilizes your system's sendmail install (or postfix). You should think about checking the logs to see if there is an problem there.



来源:https://stackoverflow.com/questions/9063517/effect-of-using-php-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!