-2

For learning purposes I want to know how to make a contact form for my website.

I did not understand something. Every person that I talk to recommend me to not use the mail() function in PHP, because there is a lot of problem with it, the mail go to spam or don't even send, but every tutorial that I see in the web is using mail() function.

I even downloaded a complete contact form from the web and they are using mail().

I even downloaded a full websites template and online stores template with all the functionality and they even use mail() function.

So I also heard about phpMailer or swiftMailer and my knowledge in OOP is not very strong but I downloaded and some tutorials and for what i realize is that this phpMailer idea is to send email from my email to some other people.

I want to receive email from the client (from contact from) to my email. What is the best way to do that? There is any snippet that I can use for my projects to learn from that?

devasia2112
  • 5,844
  • 6
  • 36
  • 56
Texture
  • 43
  • 1
  • 4
  • Why don't you test it? If it's just a contact form that only sends to you, `mail()` might work fine. If it does go to spam, whitelist it or make a rule for it to land in your inbox. The solution to the `mail()` problems you're referring to is to use an authenticated SMTP account (easily done with phpmailer, if you have the account details). – Bitwise Creative Mar 27 '16 at 07:21

1 Answers1

0

Basically after you download the phpMailer, just test the following code and adjust it at your own taste.

include 'class.phpmailer.php';

// Sendmail
$arr_mail = array(
    "email"             => "user_email@domain.tld", // user email
    "name"              => "user name",
    "system_email"      => "mail@domain.tld", // your email
    "system_from_name"  => "Your Name", // your name
    "subject"           => "Subject", 
    "message"           => "The Message",
    "message_template"  => "/path/template.html.php",
    "attachment"        => "/path/to/attachment"
);
$sendmail->sendMail($arr_mail);

Also the phpMailer class has a lot of samples, you can try each one and find what fits better to you.

devasia2112
  • 5,844
  • 6
  • 36
  • 56