Laravel Contact Form

Posted 8 months ago by zarcoder

I purchased a html template from themeforest and I'm in the process of converting all the files into blade files. Bit of a mission I must say.

I now need to setup my contact form. I'm quite lost at the moment. I did read through the Laravel mail docs but I'm struggling. So the theme included the contact form (in html obviously) as well as the php 'contact-process file. Both files are shown below.

My question is, how do I convert this to laravel? I'm not sure which steps to follow. How can I make this contact form work in laravel?

The Form:

<form method="post" id="contact-form" action='contact-process.php'>
                         <p><input type="text" name="name" class="reservation-fields" /></p>
                         <p><input type="text" name="email" class="reservation-fields"/></p>
                         <p><input type="text" name="subject" class="reservation-fields" /></p>
                         <p> <textarea name="message" id="msg-contact" class="reservation-fields" rows="7"></textarea></p>
                         <p class="antispam">Leave this empty: <input type="text" name="url" /></p>
                         <p class="contact-btn"><input type="submit" value="Send message" id="submit"/></p>

PHP File:


$recipient = "[email protected]";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

if (isset($_POST['email'])) {   
    if (preg_match('(\w[-._\w]*\[email protected]\w[-._\w]*\w\.\w{2,})', $_POST['email'])) {
        $msg = 'E-mail address is valid';
    } else {
        $msg = 'Invalid email address';

  $ip = getenv('REMOTE_ADDR');
  $host = gethostbyaddr($ip);   
  $mess = "Name: ".$name."\n";
  $mess .= "Email: ".$email."\n";
  $mess .= "Subject: ".$subject."\n";
  $mess .= "Message: ".$message."\n\n";
  $mess .= "IP:".$ip." HOST: ".$host."\n";
  $headers = "From: <".$email.">\r\n"; 
   if(isset($_POST['url']) && $_POST['url'] == ''){

       $sent = mail($recipient, $subject, $mess, $headers); 


} else {
    die('Invalid entry!');

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.