【发布时间】:2014-12-14 01:03:07
【问题描述】:
我是 laravel4 的新手,我正在开发一个网站并成功创建用户注册功能。注册后,特定用户将收到一封用于激活帐户的电子邮件,这在我的网络应用程序中绝对可以正常工作。
但问题是,验证码应该显示为超链接,而不是显示为超链接,除了 Gmail,即在其他电子邮件服务提供商(如 yahoo、outlook、GMX...)中未显示为超链接。仅显示为纯文本。
现在这是我的 mail.php 文件
<?php
return array(
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
|
*/
'driver' => 'smtp',
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => 'mail.forgroup.com',
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => 465,
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => array('address' => '******@*******.com', 'name' => '*******'),
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => 'ssl',
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => '******',
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => '*******',
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail',
/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/
'pretend' => false,
);
虽然我不知道,这个错误的原因是什么,我试图更改我的 mail.php 文件中的端口。以前我的端口值为 465,将其更改为 25 后,我收到以下错误,所以我回到了我以前的端口,即 465
Swift_TransportException
Connection could not be established with host mail.foragroup.com [ #0]
之后我尝试了另一种加密“tls”而不是“ssl”,但之后我面临以下错误
Swift_TransportException
Connection to tcp://mail.forgroup.com:465 Timed Out
现在虽然我不清楚,但我给你我的控制器,实际上我是通过它发送验证邮件的,这里是控制器
public function signupPost()
{
$validator = Validator::make(Input::all(), array(
'email' => 'required|max:255|email|unique:users',
'username' => 'required|min:4|unique:users',
'password' => 'required|min:8',
'password_again' => 'required|same:password'
)
);
if($validator->fails())
{
return Redirect::route('signup')
->withErrors($validator)
->withInput();
}else
{
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('password');
//Activation Code
$code = str_random(60);
$user = User::create(array(
'email' => $email,
'username' => $username,
'password' => Hash::make($password),
'code' => $code,
'active' => 0
)
);
if($user){
//User Activation Code Creation
Mail::send('emails.auth.activate', array('link' => URL::route('activate-account',$code), 'username' => $username),function($message) use ($user)
{
$message->to($user->email,$user->username)->subject('Activate Your Account');
});
return Redirect::route('signup')
->with('global','Your Account has been created! We have sent you an email to activate your account.Please Check the both the Inbox and Spam Folder.');
}
}
}
更新
这是我的激活 HTML 文件
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<h3>Hello <strong><h1 style="color:#1B438D">{{$username}}</h1></strong></h3> <br><br>
Please Activate Your Account Using The Following Link <br><br>
<b>NOTE</b><h3 style="color:red;">If the following code is not a link or clickable,then please <b>COPY</b><br/>
the whole code and <b>PASTE</b> it in NEW TAB of your browser.</h3>
----
{{$link}}
----
</body>
</html>
【问题讨论】:
-
您的结果电子邮件内容类型是 text/plain 还是 text/html?
-
你说的是实际包含邮件消息或正文的html文件吗?
-
你还有这个问题吗?
-
你能帮我解决这个问题吗@evoque2015
-
我认为错误出在 email/auth/activate 视图中。你如何设计你的激活按钮?你能在你的帖子上更新吗?把那个视图给我,我帮你看看。这很容易解决 - 不用担心