Sending mail with PHP
7 posts
Page 1 of 1
Hello fellow coders today i will learn you how to send emails with php. sending emails from your website can be done if your webhost supports it, you cannot test the email function on localhost.
first of, create a new php file. add this code
first of, create a new php file. add this code
Code: Select all
Why we configure the mail headers, from PHP.net
//Getting senders email with post from form.
$from = $_POST["from"];
//Where the email is sent.
$to = 'recipient email';
//The subject of the message.
$subject = 'This is my subject :o';
//The message.
$message = 'This is my message and it can contain html';
//Configuring the header, read why below.
$header = 'MIME-Version: 1.0' . '\r\n';
$header .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$header .= 'from: ' . $from;
//This will send the mail with the information we have provided.
mail($to, $subject, $message, $header);
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). Validate parameter not to be injected unwanted headers by attackers.
Nice one by the way you should add this header : Content-Transfer-Encoding:8bit
Find my programs on Softpedia
Nice tutorial.
To expand on what you send about not being able to send from localhost, by default you can't. You can change the php.ini file and configure the smtp server settings to whatever server you are sending from, for example if yuo are sending from a gmail account, configure the smtp settings to gmail's smtp server, then you should be able to send emails fine.
To expand on what you send about not being able to send from localhost, by default you can't. You can change the php.ini file and configure the smtp server settings to whatever server you are sending from, for example if yuo are sending from a gmail account, configure the smtp settings to gmail's smtp server, then you should be able to send emails fine.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
smashapps wrote:Nice tutorial.Thank you i was not aware of that cooll;
To expand on what you send about not being able to send from localhost, by default you can't. You can change the php.ini file and configure the smtp server settings to whatever server you are sending from, for example if yuo are sending from a gmail account, configure the smtp settings to gmail's smtp server, then you should be able to send emails fine.
The mail function works reliably only if the sender email is a real existing email address and also it has to be on the same server as the website. I did a little experiment with three email addresses, one from yahoo, one from gmail, and one from the same server my website was on. Only the last one worked and actually sent the email.
You can find me on Facebook or on Skype mihai_92b
XTechVB wrote:The mail function works reliably only if the sender email is a real existing email address and also it has to be on the same server as the website. I did a little experiment with three email addresses, one from yahoo, one from gmail, and one from the same server my website was on. Only the last one worked and actually sent the email.I have used multiple emails and im currently using gmail, its working fine for me. So my guess is its something with your host
I have used multiple emails and im currently using gmail, its working fine for me. So my guess is its something with your hostYeah apparently, also i mistyped something in the headers.
You can find me on Facebook or on Skype mihai_92b
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023