I want to send Email to my Email when a user views a page.
I done it successfully.
My code looks like this:
Route::any('contact_us/send', function() {
return Mail::send('contactus.send', ['name' => 'Advaith'], function($message) {
$name = $_POST['name'];
$from = $_POST['email'];
$message->to('itsme@gmail.com')->from($from, $name)->subject('Feed Back');
//itsme@gmail.com is used in this question only
});
});
This code send Email to my account.
But it is not sending the senders name and email ($name
and $from
)
I Even tried to change the variables and give a example email to it.
My .env
file looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=itsme@gmail.com
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls
My config/mail.php
file looks like this:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => 'hello@example.com',
'name' => 'Example',
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
My form which sends the data is like this:
<form class="ad-form col-md-12" method="POST" action="/contact_us/send">
{{ csrf_field() }}
<input placeholder="Name...*" type="text" name="name" required="required">
<br>
<input placeholder="Email...*" type="email" name="email" required="required">
<br>
<textarea required="required" placeholder="Your valuable feedback...*" name="comment" rows="5" cols="40"></textarea>
<br>
<input type="submit" name="submit" value="Send">
</form>
And my contactus/send.blade.php
file looks like this:
<div style="border: 2px solid orange; padding: 30px;">
<div>From: <b>{{ $_POST['name'] }}</b></div>
<div>From-Email: <b>{{ $_POST['email'] }}</b><hr></div><br>
<div style="text-align: justify;"><strong>{{ $_POST['comment'] }}</strong></div>
</div>
Please tell me why it is not sending the from address.
And please also tell me how to go to another page after the email is send.
or do you mean the from-adress in the mail header ? – shock_gone_wild Oct 11 '16 at 09:10