使用PHPMailer类发送gmail邮件实例代码:
<html>
<head>
<title>PHPMailer-发送gmail邮件_www.</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "***@gmail.com"; // GMAIL username
$mail->Password = "***"; // GMAIL password
$mail->SetFrom('****@gmail.com', 'First Last');
$mail->AddReplyTo("***@gmail.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "***@gmail.com";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
需要引入phpmailer类文件,下载地址:PHPMailer邮件发送类V5.1下载地址。
您可能感兴趣的文章:
PHPMailer发送邮件的实例分享
phpmailer发送网易126邮箱的例子
phpmailer发送yahoo邮件的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPmailer发送邮件及乱码问题的解决
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
使用phpmailer发送邮件的例子
一个var_dump用法的例子,如下:
<?php /** * var_dump用法举例 * edit www. */ $a = "alsdflasdf;a"; $b = var_dump($a); echo "<br>"; //var_dump($c); $d=var_dump($c); echo "<br>"; echo $a; echo "<br>"; echo $b; echo "<br>"; ?>
输出:
string(12) "alsdflasdf;a"
NULL
alsdflasdf;a
说明:
var_dump()方法,判断一个变量的类型与长度,并输出变量的数值,如果变量有值,则输出是变量的值,并返回数据类型。
显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。
格式:var_dump ( mixed expression [, mixed expression [, ...]] )
语法:
var_dump (var,var,bar);
注意:
用保证var_dump中的变量必须是存在的,如果变量存在但值是空,则返回false;
没有变量时,则返回NULL。
该函数有输出的功能,因此不必加其它的输出函数。
1,addcslashes() 函数
PHP String 函数
定义和用法
addcslashes() 函数在指定的字符前添加反斜杠。
语法
addcslashes(string,characters)
参数 描述
string 必需。规定要检查的字符串。
characters 可选。规定受 addcslashes() 影响的字符或字符范围。
提示和注释
注释:在对 0,r,n 和 t 应用 addcslashes() 时要小心。在 PHP 中,\0,\r,\n 和 \t 是预定义的转义序列。
例子:
//向字符串中的特定字符添加反斜杠
$str = "Hello, my name is John Adams.";
echo $str;
echo addcslashes($str,'m');
echo addcslashes($str,'J');
?>
输出:
Hello, \my na\me is John Ada\ms.
Hello, my name is \John Adams.
2,addslashes()函数
PHP String 函数
定义和用法
addslashes() 函数在指定的预定义字符前添加反斜杠。
这些预定义字符是:
双引号 (")
反斜杠 (\)
NULL
语法
addslashes(string)
参数 描述
string 必需。规定要检查的字符串。
提示和注释
提示:该函数可用于为存储在数据库中的字符串以及数据库查询语句准备合适的字符串。
注释:默认情况下,PHP 指令 magic_quotes_gpc 为 on,对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使
用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。
例子:
//向字符串中的预定义字符添加反斜杠
$str = "Who's John Adams?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>
输出:
Who\'s John Adams? This is safe in a database query.
对于函数addslashes()和addclashes(),都有对应的去除反斜杠的方法,分别为:stripcslashes()函数和stripslashes()函数。有兴趣的朋友,也可以研究下。