adityar15/contactform

使用 Livewire 和 Tailwind CSS 开发的联系表单包

v1.0 2021-03-08 19:59 UTC

This package is auto-updated.

Last update: 2024-09-09 20:49:53 UTC


README

当用户填写详细信息并点击发送消息时,您将收到您指定的电子邮件地址的电子邮件。它使用 Livewire 和 Tailwind CSS 构建

先决条件

Livewire 2.x

安装

安装请使用以下命令

composer require adityar15/contactform

发布视图和配置文件

安装后,发布配置和视图文件。

php artisan vendor:publish --provider="adityar15\contactform\ContactFormServiceProvider"

Blade 文件更改

在您的 blade 文件中包含 tailwind cdn

<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">

现在在同一个 blade 文件中,您想要添加联系表单的地方,只需包含这两行

  @livewire('adityar15contactform')
  @livewireScripts
  

用法

如果您不希望使用 Tailwind 并有自己的自定义样式,您可以通过编辑 blade 文件来实现。

您可以通过编辑 resources/views/vendor/contactform/contactform.blade.php 中的视图文件来编辑表单的样式。您还可以从 resources/views/vendor/contactform/emailtemplate.blade.php 中的视图文件编辑电子邮件模板

或者,您也可以通过配置文件更改电子邮件模板。配置文件名为 contactform.php。

<?php


return [
    'mail'=>[
        'mail_to' => env('MAIL_FROM_ADDRESS'),
        'mail_to_name'=> 'admin'
    ],

    'emailtemplate'=>'vendor.contactform.emailtemplate', 
	/**email template. Insert the blade file name which you want to be rendered for email. In this case emailtemplate is file located in side resources/views/vendor/contactform **/

    'subject_line' =>'Someone contacted you on your website',
	// subject line for your email
	
    'thankyou_message' => 'Thank you for contacting us. We will get back to you shortly.'
	//thank you message displayed to the user after successfull form submission
];

如果您使用自定义电子邮件模板,请注意在电子邮件 blade 文件中添加以下变量

$name 代表你的名字,$body 代表消息,$fromname 代表联系你的用户的名字,$fromemail 代表联系你的用户的电子邮件

截图

alt text