search
HomeBackend DevelopmentPHP Tutorialamazon-ses - 初哥请教php环境下如何使用amazon SES

你好,我的网站需要发送激活邮件,目前使用的是smtp,很多都进了垃圾箱,我注册了amazon ses,但搞不得怎么使用,我想请教下php环境下如何使用amazon ses的,我见 segmentfault这个网站也是使用了这个服务

amazon-ses - 初哥请教php环境下如何使用amazon SES
另外补充两个问题,如何设置发件人名字,如上述图片中的SegmentFault问答社区

还有就是如何发html邮件,我这样设置不行的:

$m->setMessageFromString('','我是哥This is the message body.<br><img  src="http://www.AAA.com/images/indexlogo.jpg" border="0" alt="amazon-ses - 初哥请教php环境下如何使用amazon SES" >');

收到的邮件只有:我是哥This is the message body.后面的内容则没有

回复内容:

你好,我的网站需要发送激活邮件,目前使用的是smtp,很多都进了垃圾箱,我注册了amazon ses,但搞不得怎么使用,我想请教下php环境下如何使用amazon ses的,我见 segmentfault这个网站也是使用了这个服务

amazon-ses - 初哥请教php环境下如何使用amazon SES
另外补充两个问题,如何设置发件人名字,如上述图片中的SegmentFault问答社区

还有就是如何发html邮件,我这样设置不行的:

$m->setMessageFromString('','我是哥This is the message body.<br><img  src="http://www.AAA.com/images/indexlogo.jpg" border="0" alt="amazon-ses - 初哥请教php环境下如何使用amazon SES" >');

收到的邮件只有:我是哥This is the message body.后面的内容则没有

要使用ses服务首先你得确保开通了此服务,假设你已经申请开通了ses,并已经获取了"Access Key"和"Secret Key"

然后你需要先下载一个库文件http://aws.amazon.com/code/Amazon-SES...,第一次使用需要先验证你是否是发件箱的所有者,你需要执行下列代码

require_once 'ses.php';
$ses = new SimpleEmailService('Access Key Here', 'Secret Key Here');

// 这里填你需要作为发件箱的邮箱地址,这个地址必须存在,因为它会发一封邮件过去验证
print_r($ses->verifyEmailAddress('user@example.com'));

如果成功的话,会返回类似下面的内容

Array
(
  [RequestId] => 1b086469-291d-11e0-85af-df1284f62f28
)

这时候,登录到你刚才填写的邮箱里去,你会收到一封验证邮件,点击邮件里的验证链接即可完成验证步骤。

但是注意,这时候你还只能向自己发送邮件,不能其他任何第三方邮箱发送,因为此时你只是开发者状态,如果你需要向其他用户发送邮件,你需要向亚马逊“提出生产环境权限申请(Request Production Access)”。

点击这个链接提交申请,可能需要你填写每天发送的限额,你可以根据自己的需要申请,反正以后也是可以调整的。

需要注意的是你的限额不是一部到位的,也就是说如果你提出每天发送1万封邮件的限额,那么你第一天大概只能发送100封,然后第二天发送500封,以此类推,大概一周后你就可以发送一万封邮件了。这也是为了防止垃圾邮件制造者滥用这一服务。申请是人工审核的,所以需要等待一会,不过也没有几个小时。

当这一切都完成的了后,你就可以正常使用ses了,这里有php代码的示例,非常简单http://www.orderingdisorder.com/aws/s...

update

发送中文的问题,只需要设置下编码即可

$m = new SimpleEmailServiceMessage();
$m->addTo('recipient@example.com');
$m->setFrom('user@example.com');
$m->setSubject('我是中文标题');
$m->setMessageFromString('我是中文内容.');

// 再这里设置标题和内容编码
$m->setSubjectCharset('UTF-8');
$m->setMessageCharset('UTF-8');

print_r($ses->sendEmail($m));
update

如果需要发送的是html内容,则需要使用setMessageFromString的第二个参数,这是专门用来发送html内容的,比如

// 第一个参数可以留空
$m->setMessageFromString(NULL, '<h1 id="这是html的测试">这是html的测试</h1><p>只是一个测试</p>');

如果要设置发送人名称的话,可以在setFrom的时候按照'发件人名称 '的格式来设置,比如

$m->setFrom('Joyqi <test>');</test>

但是如果你要把上面的Joyqi换成中文的话就会出现乱码,这时候你需要自己用base64_encode手动编码下,并指定编码格式,比如

// 编码函数
function address_encode($str) {
    return '=?UTF-8?B?' . base64_encode($str) . '?=';
}

$m->setFrom(address_encode('测试中文发件人') . ' <test>');</test>

好的,谢谢了,下载一个库文件,这个库页面打不开,是不是ses.php?如果是的话我去其他地方下载,你最后提到的例子连接里面有

很简单,很好用!

Notice: Undefined property: SimpleEmailServiceRequest::$resource in C:\xampp\htdocs\husili\email\ses.php on line 491

Warning: SimpleEmailService::sendEmail(): 60 SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in C:\xampp\htdocs\husili\email\ses.php on line 357

Statement
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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

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 Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),