使用限制
Windows操作系统增强版云虚拟主机不支持发送邮件。
前提条件
确认PHP函数的fsockopen参数为启动状态。
说明 PHP函数的fsockopen参数默认为启动状态。如需修改该参数状态,具体操作,请参见设置PHP.INI参数。
 操作步骤
联系邮箱服务商获取使用SSL加密方式发送邮件的配置信息。
涉及的主要配置项如下所示:
配置项  | 说明  | 
发邮件服务器地址  | 输入服务器邮箱地址。例如,a***.example.com。  | 
发邮件服务器端口号  | 加密端口一般是465端口。  | 
邮箱用户名  | 可能是Email地址,也可能是Email地址前缀,具体可咨询邮箱服务商。  | 
邮箱客户端密码  | 部分邮箱服务商Web浏览器登录界面的登录密码和客户端密码并不相同,可能需要单独设置,具体可咨询邮箱服务商。  | 
在本地主机使用客户端软件(Outlook、Foxmail等),使用已获取的邮件配置信息设置本地客户端,并发送邮件测试。
说明 如果邮件发送失败,表示获取的配置信息不正确,您需要联系邮箱服务商解决。
 根据实际的开发语言选择对应的程序样例,并将程序样例下载到本地。
程序样例如下所示:
.NET源程序样例
截取部分源程序样例如下:
MailMessage mmsg = new MailMessage();
mmsg.Subject = "主题";                //邮件主题
mmsg.BodyFormat = MailFormat.Html;
mmsg.Body = "正文";                   //邮件正文
mmsg.BodyEncoding = Encoding.UTF8;    //正文编码
mmsg.Priority = MailPriority.High;    //优先级
mmsg.From = "a***@example.com";       //发件人邮箱地址
mmsg.To = "b***@example.com";         //收件人邮箱地址
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "test01");  //用户名
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123****"); //密码
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);     //端口 
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");      //使用SSL
System.Web.Mail.SmtpMail.SmtpServer = "smtp.****.com";                                     //smtp服务器
SmtpMail.Send(mmsg);
PHP源程序样例
截取部分源程序样例如下:
<?php
require 'PHPMailerAutoload.php';
require_once('class.phpmailer.php');
require_once("class.smtp.php");
$mail = new PHPMailer();
$mail->CharSet="UTF-8";           //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置为 UTF-8
$mail->IsSMTP();                  //设定使用SMTP服务
$mail->SMTPAuth = true;           //启用SMTP验证功能
$mail->SMTPSecure = "ssl";        //启用SSL
$mail->SMTPDebug = 2;
$mail->Host = "smtp.****.com";    //SMTP服务器
$mail->Port = 465;                //SMTP服务器的端口号
$mail->Username = "test01";                                      //SMTP服务器用户名
$mail->Password = "123****";                                     //SMTP服务器密码
$mail->SetFrom('a***@example.com', 'a***');                      //设置发件人地址和名称
$mail->AddReplyTo("b***@example.com","b***");                    //设置邮件回复人地址和名称
$mail->Subject = '邮件标题';                                      //设置邮件标题
$mail->AltBody = "为了查看该邮件,请切换到支持HTML的邮件客户端"; //可选项,向下兼容考虑
$mail->MsgHTML('<html>helo</html>');                             //设置邮件内容
$mail->AddAddress('c***@example.com', "c***");
$mail->AddAttachment("images/phpmailer.gif");                    //附件
if(!$mail->Send()) {
    echo "发送失败:" . $mail->ErrorInfo;
} else {
    echo "恭喜,邮件发送成功!";
}
?>
ASP源程序样例
截取部分源程序样例如下: 
<%
Set Mail = CreateObject("CDO.Message")
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.****.com"
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="test01"
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="123****"
Mail.Configuration.Fields.Update
Mail.Subject="Email subject"
Mail.From="a***@example.com"
Mail.To="b***@example.com"
Mail.TextBody="This is an email message."
Mail.Send
Set Mail = Nothing
%>
<%="发送成功!!!"%>
使用已通过测试的配置信息,编写程序样例中的邮箱服务器配置项。
将编写好的程序通过FileZilla工具上传到云虚拟主机上,并实际发送邮件测试。
程序上传到云虚拟主机的具体操作,请参见通过FileZilla管理网站程序文件。