Table of Contents
邮件送信Zend_Mail
Home Backend Development PHP Tutorial 【急救】使用Zend_Mail构建邮件送信表单,smtp有有关问题

【急救】使用Zend_Mail构建邮件送信表单,smtp有有关问题

Jun 13, 2016 pm 01:45 PM
gmail gt lt mail quot

【急救】使用Zend_Mail构建邮件送信表单,smtp有问题
今天写了一段代码,使用Zend_Mail构建邮件送信表单,程序始终运行不成功,我怀疑是我的smtp配置的存在问题,实际运行时
$smtp = new Zend_Mail_Transport_Smtp("smtp.gmail.com",
array(
'port' => '25',
'auth' => 'login',
'username' => 'XXXX@gmail.com',
'password' => 'XXXXX'
));
username,password均使用真实的可用的邮箱,其各位兄弟帮忙看看问题在哪里,3Q
整体代码如下:



邮件送信


邮件送信Zend_Mail























To:
邮件名:
添加文件:
正文:





function encode($str){
return mb_convert_encoding($str, "gb2312","auto");
}
if($_POST['submit'] != null){
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$smtp = new Zend_Mail_Transport_Smtp("smtp.gmail.com",
array(
'port' => '25',
'auth' => 'login',
'username' => 'XXXX@gmail.com',
'password' => 'XXXXX'
));
Zend_Mail::setDefaultTransport($smtp);

$mail = new Zend_Mail();
$mail->addTo($_POST['to']);
$mail->setForm("Circleinthehouse@gmail.com",encode("田家"));
$mail->setSubject(encode($_POST['subject']));
$mail->setBodyHtml(encode($_POST['body']));
$attach = $mail->createAttachment(file_get_contents($_FILES['fl']['tmp_name']));
$attach->type = $_FILES['fl']['type'];
$attach->filename = $_FILES['fl']['name'];
$mail->send();
print("邮件发送成功!");
}
?>




------解决方案--------------------
SMTP端口错误,GMAIL的端口并不是25,参考GMAIL官方说明:

配置其他邮件客户端说明

标准说明:

在 Gmail 中启用 POP。操作完成后不要忘记点击保存更改。
将您的客户端配置为与以下设置匹配:
接收邮件 (POP3) 服务器 - 需要 SSL: pop.gmail.com
使用 SSL:是
端口:995
发送邮件 (SMTP) 服务器 - 需要 TLS 或 SSL: smtp.gmail.com(使用身份验证)
使用身份验证:是
TLS/STARTTLS 的端口:587
SSL 的端口:465
帐户名: 您的完整电子邮件地址(包括 @gmail.com 或 @your_domain.com)
电子邮件地址: 您的电子邮件地址(username@gmail.com 或 username@your_domain.com)
密码: 您的 Gmail 密码
------解决方案--------------------
array(
'port' => '25',
'auth' => 'login',
'username' => 'XXXX@gmail.com',
'password' => 'XXXXX'
));


修改为:

PHP code

1

2

3

4

5

6

7

8

9

10

11

12

array(

'port' => '587',

'auth' => 'login',

'username' => 'XXXX@gmail.com',

'password' => 'XXXXX'

));

 <div class="clear">

                  

               

               

         

            </div>

Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add a hyperlink to text or image in Gmail How to add a hyperlink to text or image in Gmail May 06, 2023 pm 06:07 PM

No matter how many instant messaging apps have come and gone, email always has a completely different feel to it. Mailing is truly synonymous with Gmail. Not to mention a professional front desk, Gmail is unavoidable, just unavoidable! Since Gmail is used so frequently, no matter what, you have to know how to make your Gmail experience the smoothest and most efficient. You will most likely need to add a lot of web links in the body of your email, and it will definitely look unwieldy if you have so many links. But links are definitely necessary, even if long links will definitely make your email look ugly. So is there a way out? What about hyperlinks? How do you hide a link in text or an image? Sound cool? Oh yes, Gmail is

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

How to remove Boomerang from Gmail on PC or mobile How to remove Boomerang from Gmail on PC or mobile Apr 14, 2023 pm 10:46 PM

How to Remove Boomerang from Gmail Find below our step-by-step guide to remove Boomerang from your Gmail account on your PC or mobile phone. To remove Boomerang from Gmail on PC, open Google Chrome browser on your computer. In Google Chrome, click the three-dot icon in the upper right corner of the screen. Select More Tools from the drop-down menu. Click Extensions from the next drop-down menu. On the Extensions screen, look for

How to set Gmail to delete instead of archive in the Mail app on iPhone and iPad How to set Gmail to delete instead of archive in the Mail app on iPhone and iPad Apr 13, 2023 pm 02:34 PM

Have you noticed that when you try to delete a message in Gmail on iOS, you only see the archive option? Read on to learn how to delete Gmail on iPhone without archiving it in the Mail app. The setting to change the default option for archiving Gmail emails using the Mail app on iPhone and iPad is completely hidden in Settings, but it can be changed quickly once you know where to go. Keep in mind that this tutorial is for people using Gmail through the Apple Mail app on iPhone and iPad. Another option is to use the Gmail app on your iPhone/iPad. you even

How to remove autocomplete email addresses in Gmail How to remove autocomplete email addresses in Gmail Apr 21, 2023 am 10:46 AM

Gmail is the most popular web-based email server from Google, and it comes with many powerful features that are helpful when browsing, editing, and sending emails. One such feature is the autocomplete list, which allows users to view a list of email addresses saved as contacts before finishing entering the full address. This feature is really useful but sometimes it may not be a good approach as there may be some email addresses that are no longer valid or may have been deleted by the user. For example, someone who leaves an organization no longer has access to a company email address. But there is a way to remove those email addresses that are highlighted in Gmail's autocomplete list. If you also want to remove emails from Gmail autocomplete list

Google Gemini now in the Gmail app: Smart email search via AI on Android devices Google Gemini now in the Gmail app: Smart email search via AI on Android devices Aug 31, 2024 am 09:54 AM

Google is expanding its Gmail app at Android with an AI-powered Q&A function which was already available in the web version of Gmail and is powered by Google's Gemini AI assistant. Users can now search their inbox more efficiently by asking speci

How to use Gmail on iPhone to find and recover archived emails How to use Gmail on iPhone to find and recover archived emails Apr 26, 2023 am 10:52 AM

On your iPhone, are you trying to find old emails archived in Gmail but are unable to do so? You are not alone, so don't worry. Many people face difficulties finding and recovering old emails on their mobile devices. In this blog post, we will walk you through the process of finding and recovering archived emails in Gmail on iPhone. We'll also provide tips and tricks to help you keep your inbox organized and find important emails more easily in the future. So whether you're trying to retrieve important business emails or sentimental messages from loved ones, you'll learn how to easily access and recover archived emails. Archive your emails in Gmail Step 1: On iP

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

See all articles