用PHPMailer发送邮件,根据例子敲了如下代码
require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录$mail = new PHPMailer(); //建立邮件发送类//$address = $_POST['address'];$mail->IsSMTP(); // 使用SMTP方式发送$mail->Host = "mail.qq.com";// 您的企业邮局域名$mail->Port = '25';//$mail->SMTPAuth = true; // 启用SMTP验证功能$mail->Username = "497045318@qq.com"; // 邮局用户名(请填写完整的email地址)$mail->Password = "******"; // 邮局密码$mail->From = "497045318@qq.com"; //邮件发送者email地址$mail->FromName = "Frank Tung";$mail->AddAddress("tongzhenhang@qq.com");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")//$mail->AddReplyTo("", "");//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件//$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式$mail->Subject = "PHPMailer测试邮件"; //邮件标题$mail->Body = "Hello,这是测试邮件"; //邮件内容$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略if(!$mail->Send()){ echo "邮件发送失败. <p>"; echo "错误原因: " . $mail->ErrorInfo; exit;}echo "邮件发送成功";
结果出现
邮件发送失败.
错误原因: The following From address failed: 497045318@qq.com : Called Mail() without being connected
我尝试把class.phpmailer.php中的
/**
* Method to send mail: ("mail", "sendmail", or "smtp").
* @var string
*/
var $Mailer = 'mail';
改成
var $Mailer = 'smtp';
此错误依旧。
我再去搜索QQ的smtp,网页如下
http://kf.qq.com/faq/120322fu63YV130422nqIrqu.html
将$mail->Host = "mail.qq.com";
改成
$mail->Host = "smtp.qq.com";
$mail->Port = '465';
还是报错。
改成
$mail->Port = '587';
报错信息:
邮件发送失败.
错误原因: The following From address failed: 497045318@qq.com : MAIL not accepted from server,530,Must issue a STARTTLS command first.
SMTP server error: Must issue a STARTTLS command first.
SMTP server error: Must issue a STARTTLS command first.
我Youtube了一个教学视频
InMotion Hosting - How to use PHPMailer
https://www.youtube.com/watch?v=JltHLzkghmY
我的代码与他基本一样,与之唯一的区别是我在本地电脑localhost,而不是在服务器上(我还没个人的服务器)我想是不是与这个因素相关。
我想请教各位这是什么原因。十分感谢!如果还有什么好的方法/代码可以用php发送邮件,也请教各位了!
回复讨论(解决方案)
原因已经找到了。
因为当时在测试功能时候,由于一直各种跳错,我就去一行行排错。
//$mail->SMTPAuth = true; // 启用SMTP验证功能
在排错时候,我把上面一行注释掉了,最后忘了把注释去掉。
所以这一行不可或缺。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment