Latest web development tutorials
×

PHP Kurs

PHP Kurs PHP Kurze Einführung PHP installieren PHP Grammatik PHP Variable PHP echo/print PHP Datentypen PHP Konstante PHP Schnur PHP Die Betreiber PHP If...Else PHP Switch PHP Feld PHP Sortieren eines Array PHP Superglobals PHP While Verkehr PHP For Verkehr PHP Funktion PHP Magische Variablen PHP Namespaces PHP Objektorientiert

PHP Form

PHP Form PHP Formularauthentifizierung PHP Form - Erforderliche Felder PHP Form - Überprüfung E-Mail und URL PHP Komplette Formularinstanz PHP $_GET Variable PHP $_POST Variable

PHP Erweiterte Tutorial

PHP Mehrdimensionale Arrays PHP Datum PHP enthalten PHP Datei PHP Datei-Upload PHP Cookie PHP Session PHP E-mail PHP Sicherheit E-mail PHP Error PHP Exception PHP Filter PHP Erweiterte Filter PHP JSON

PHP 7 Neue Funktionen

PHP 7 Neue Funktionen

PHP Datenbank

PHP MySQL Kurze Einführung PHP MySQL Verbindung PHP MySQL Erstellen einer Datenbank PHP MySQL Erstellen Sie eine Datentabelle PHP MySQL einfügen von Daten PHP MySQL Legen Sie mehrere Daten PHP MySQL Prepared Statements PHP MySQL Lesen Sie Daten PHP MySQL WHERE PHP MySQL ORDER BY PHP MySQL UPDATE PHP MySQL DELETE PHP ODBC

PHP XML

XML Expat Parser XML DOM XML SimpleXML

PHP & AJAX

AJAX Kurze Einführung AJAX PHP AJAX Datenbank AJAX XML AJAX Echtzeitsuche AJAX RSS Reader AJAX Abstimmung

PHP Referenzhandbuch

PHP Array PHP Calendar PHP cURL PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP PDO PHP SimpleXML PHP String PHP XML PHP Zip PHP Timezones PHP Bildverarbeitung PHP RESTful

PHP mail () Funktion

PHP Mail-Referenzhandbuch Füllen Sie PHP Mail - Referenzhandbuch

Definition und Verwendung

mail () Funktion ermöglicht es Ihnen, E-Mail direkt aus einem Skript zu senden.

Wenn die E-Mail-Zustellung erfolgreich angenommen wird, liefert TRUE, ansonsten FALSE zurück.

Grammatik

mail(to,subject,message,headers,parameters)

参数 描述
to 必需。规定电子邮件的接收者。
subject 必需。规定电子邮件的主题。注释:该参数不能包含任何换行字符。
message 必需。定义要发送的消息。用 LF(\n)将每一行分开。行不应超过70个字符。

Windows 注释:当 PHP 直接连接到 SMTP 服务器时,如果在消息的某行开头发现一个句号,则会被删掉。要解决这个问题,请将单个句号替换成两个句号:
<?php
$txt = str_replace("n.", "n..", $txt);
?>

headers 可选。规定额外的报头,比如 From、Cc 和 Bcc。附加标头应该用 CRLF(\r\n)分开。

注释:发送电子邮件时,它必须包含一个 From 标头。可通过该参数进行设置或在 php.ini 文件中进行设置。

parameters 可选。规定 sendmail 程序的额外参数(在 sendmail_path 配置设置中定义)。例如:当 sendmail 和 -f sendmail 的选项一起使用时,sendmail 可用于设置发件人地址。


Tipps und Hinweise

Hinweis: Sie müssen sich daran erinnern , dass E-Mail - Zustellung akzeptiert wird, bedeutet nicht , dass E-Mail an das Zielprogramm ankommt.


Beispiel 1

Senden Sie eine einfache E-Mail:

<?php
$txt = "First line of textnSecond line of text";

// Use wordwrap() if lines are longer than 70 characters
$txt = wordwrap($txt,70);

// Send email
mail("[email protected]","My subject",$txt);
?>


Beispiel 2

Senden Sie E-Mail mit zusätzlichen Header:

<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "rn" .
"CC: [email protected]";

mail($to,$subject,$txt,$headers);
?>


Beispiel 3

Senden Sie eine HTML-E-Mail:

<?php
$to = "[email protected], [email protected]";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-版本: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";

// More headers
$headers .= 'From: <[email protected]>' . "rn";
$headers .= 'Cc: [email protected]' . "rn";

mail($to,$subject,$message,$headers);
?>


PHP Mail-Referenzhandbuch Füllen Sie PHP Mail - Referenzhandbuch