<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Php Archives</title>
	<atom:link href="https://www.johnpatel.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>SEO, WordPress, Make Money, Online Jobs, Reviews</description>
	<lastBuildDate>Sun, 02 Jun 2019 11:07:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">145939692</site>	<item>
		<title>PHP Mail Function &#8211; PHP Send Email Using mail() Function</title>
		<link>https://www.johnpatel.com/php-mail-function/</link>
		
		<dc:creator><![CDATA[JP]]></dc:creator>
		<pubDate>Sun, 02 Jun 2019 11:07:58 +0000</pubDate>
				<category><![CDATA[Php]]></category>
		<guid isPermaLink="false">https://www.johnpatel.com/?p=1428</guid>

					<description><![CDATA[<p>Are you looking for a technique to send an email in PHP? In this article, I will show you how you can send an email using PHP. Generally, you have to use the PHP Mail Function to do it. PHP Send Email Using mail() Function is the golden key to send emails very easily. Let&#8217;s [&#8230;]</p>
<p>The post <a href="https://www.johnpatel.com/php-mail-function/">PHP Mail Function &#8211; PHP Send Email Using mail() Function</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Are you looking for a technique to send an email in PHP? In this article, I will show you how you can send an email using PHP. Generally, you have to use the <strong>PHP Mail Function</strong> to do it. PHP Send Email Using mail() Function is the golden key to send emails very easily. </p>
<p>Let&#8217;s discuss the definition and syntax of mail() function and how we can implement in PHP projects. Just read this article till the end. I am sure you will get your solution in this tutorial.</p>
<p>Basically, this function uses the inbuilt <strong>SMTP service</strong> to perform an action. Another advantage is there is no need for a server connection.  </p>
<h2>PHP Mail Function &#8211; PHP Send Email Using mail() Function</h2>
<p><img decoding="async" src="https://www.johnpatel.com/wp-content/uploads/2019/06/PHP-Mail-Function-PHP-Send-Email-Using-mail-Function.jpg" alt="PHP Mail Function - PHP Send Email Using mail() Function" title="PHP Mail Function - PHP Send Email Using mail() Function"/></p>
<p>First of all, I will show you how to write the <strong>PHP mail function</strong> inside your code.</p>
<pre>
<xmp>
<?php

// Receiver's Email
$to = "info@johnpatel.com";

// Subject Line
$subject = "Subject Test";

// Email body message
$txt = "This is testing!";

// PHP mail finction
mail($to,$subject,$txt,$headers);

?>
</xmp>
</pre>
<h4>Definition:</h4>
<p>PHP Send Email Using mail() Function will allow you to send emails directly from the coding/script. </p>
<p>Now you will think what do you mean directly? Directly means you don&#8217;t have to use any third party script to send email in PHP. PHP mail() function is inbuilt function of PHP programming language. It will connect to the server directly. Even more, no need to use SMTP details to use it. Because mail() function automatically uses Simple Mail Transmission Protocol (SMTP) to send Email PHP.</p>
<h4>Syntax:</h4>
<pre>
<xmp>
mail('to', 'your-subject', 'text-message', $headers, 'additional-parameters');
</xmp>
</pre>
<p>Now, let&#8217;s take deep information of all the parameters which are used in mail() function.</p>
<table>
<tr>
<th class="bold bg-orange">Parameters</th>
<th class="bold bg-orange">Description</th>
</tr>
<tr>
<td class="bold green">to</td>
<td>Email receiver&#8217;s Email address. <b>Note:</b> It&#8217;s a mendetory field.</td>
</tr>
<tr>
<td class="bold green">your-subject</td>
<td>It specifies the subject of the Email. <b>Note:</b> It&#8217;s a Required field and can not contain newline. You have to write subject in single line.</td>
</tr>
<tr>
<td class="bold green">text-message</td>
<td>It is also a required field. It defines the text message or body message of the email. You can write your text message in this parameter. <strong>(Must not exceed 70 characters in a single line)</strong> Even more, you can write <a href="https://en.wikipedia.org/wiki/HTML" rel="noopener noreferrer" target="_blank">HTML</a> code in this field. But first of all, you must have to write HTML header code in mail function. And it is our next parameter.</td>
</tr>
<tr>
<td class="bold green">$headers</td>
<td>It is optional field. Mainly, it is use to define From, Cc, and Bcc. Also, it helps to allow html code in &#8216;text-message&#8217;. The additional headers is separated with a CRLF (\r\n)</td>
</tr>
<tr>
<td class="bold green">additional-parameters</td>
<td>It is also an optional field. You can write additional things in this field.</td>
</tr>
</table>
<p>Above all, parameters are very important in mail() function. Without these parameters, you can&#8217;t send the email to anyone.</p>
<p>Now, Let&#8217;s take some examples to show you how to implement this function inside coding.</p>
<h5>1. Send email in PHP with Extra Header</h5>
<p>You can send email to two different person with following code snippet.</p>
<pre>
<xmp>
<?php
$to = "info@example.com";
$subject = "Test subject";
$txt = "This is test";
$headers = "From: noreply@example.com" . "\r\n" .
"CC: second-person@example.com";

mail($to,$subject,$txt,$headers);
?>
</xmp>
</pre>
<h5>2. PHP Send Email with HTML Code</h5>
<pre>
<xmp>
<?php
$to = "info@example.com";
$subject = "Test HTML Email";

$html_message = "
<html>
  <head>
    <title>Test HTML Email</title>
  </head>
<body>
  <p>This is testing HTML Email.</p>
  <table>
    <tr>
     <th>Name</th>
     <th>Age</th>
    </tr>
    <tr>
      <td>John</td>
      <td>27</td>
    </tr>
  </table>
</body>
</html>
";

// Must set content-type when sending HTML email. It allows HTML code.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// Additional headers
$headers .= 'From: <noreply@example.com>' . "\r\n";
$headers .= 'Cc: second-person@example.com' . "\r\n";

mail($to, $subject, $html_message ,$headers);
?>
</xmp>
</pre>
<p>I hope you are now a clear vision of <strong>PHP Mail Function</strong> and how to send email using mail() function very easily. If you like this tutorial, please share it.</p>
<p><b></b></p>
<ul>
<li><a href="https://www.johnpatel.com/pagination-in-php-function-search-filter/">Pagination in PHP using Function</a></li>
<li><a href="https://www.johnpatel.com/php-foreach-loop/">PHP Foreach Loop</a></li>
<li><a href="https://www.johnpatel.com/generate-unique-password-using-php-function/">Generate unique password using PHP function</a></li>
</ul>
<p>The post <a href="https://www.johnpatel.com/php-mail-function/">PHP Mail Function &#8211; PHP Send Email Using mail() Function</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1428</post-id>	</item>
		<item>
		<title>PHP Foreach Loop Implementation with Example</title>
		<link>https://www.johnpatel.com/php-foreach-loop/</link>
		
		<dc:creator><![CDATA[JP]]></dc:creator>
		<pubDate>Mon, 24 Dec 2018 10:21:35 +0000</pubDate>
				<category><![CDATA[Php]]></category>
		<guid isPermaLink="false">https://www.johnpatel.com/?p=914</guid>

					<description><![CDATA[<p>Hello friends, In this tutorial we will discuss PHP Foreach Loop Implementation. Even more, we will give you some examples for better understand. First of all, let&#8217;s discuss what is foreach in PHP and how to use in a project? The foreach loop is used to print array values alternatively. It works same like &#8220;While [&#8230;]</p>
<p>The post <a href="https://www.johnpatel.com/php-foreach-loop/">PHP Foreach Loop Implementation with Example</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hello friends, In this tutorial we will discuss <strong>PHP Foreach Loop Implementation</strong>. Even more, we will give you some examples for better understand.</p>
<p><img decoding="async" src="https://www.johnpatel.com/wp-content/uploads/2018/12/PHP-Foreach-Loop-Implementation.jpg" alt="PHP Foreach Loop Implementation with Example" title="PHP Foreach Loop Implementation with Example"></p>
<p>First of all, let&#8217;s discuss what is foreach in PHP and how to use in a project?</p>
<p>The foreach loop is used to print array values alternatively. It works same like &#8220;While Loop&#8221;. But the difference is foreach works to print array values and while is used to fetch rows from MySQL database.</p>
<h2>PHP Foreach Syntax</h2>
<p>This is the basic syntax of foreach. <strong>$array</strong> tens for array values and <strong>$value</strong> returns the array values one by one.</p>
<pre><xmp>
foreach($array as $value)
{
   echo $value;
}
</xmp>
</pre>
<p>Now let&#8217;s take one example to get more idea.</p>
<h4>Example1:</h4>
<pre><xmp>
$array = array("ABC","XYZ","PQR");

foreach($array as $value)
{
   echo 'The value is '.$value;
   echo "< br />"
}
</xmp>
</pre>
<h4>Output:</h4>
<pre><xmp>
The value is ABC
The value is XYZ
The value is PQR
</xmp>
</pre>
<p>In above example you can see we have take one array which have values ABC,XYZ and PQR. Then we have use the PHP foreach loop to print all the array values.<br />
<strong>echo &#8220;&lt; br /&gt;&#8221;</strong> is used to print results in new line. As a result, you will get the result and it shows in output section above.</p>
<p>You can store individual values in one other array and print it manually. I will show you how it is possible in below example.</p>
<h4>Example2:</h4>
<pre><xmp>
$array = array("ABC","XYZ","PQR");

$print = array();
foreach($array as $value)
{
   $print[] = $value;
}
	
echo $print[0];
echo "< br />";

echo $print[1];
echo "< br />";

echo $print[2];
</xmp>
</pre>
<h4>Output:</h4>
<pre><xmp>
ABC
XYZ
PQR
</xmp>
</pre>
<p>First we have take one other array name &#8220;print&#8221; and store foreach values in this array. Then you can print this array values manually as you want. Like $print[0], $print[1] and $print[2].</p>
<p>$print[0] gives first value of array rather $print[1] gives second value and so on&#8230; Generally, this method is better for while loop array values. But we can use it in <a href="https://en.wikipedia.org/wiki/Foreach_loop" target="_blank" rel="noopener noreferrer">foreach</a> also.</p>
<p>I hope you have understood the foreach loop tutorial and it will help you in live projects. Thanks for reading and if you like it please share it.</p>
<p><strong>Read this article also:</strong></p>
<ul>
<li><a href="https://www.johnpatel.com/pagination-in-php-function-search-filter/">Pagination in PHP Function With Search Filter</a></li>
<li><a href="https://www.johnpatel.com/generate-unique-password-using-php-function/">Generate unique password using PHP function</a></li>
<li><a href="https://www.johnpatel.com/change-content-and-url-without-refreshing-page/">Change content and URL without refreshing page</a></li>
<li><a href="https://www.johnpatel.com/compress-images-in-php/">How to reduce or compress images in PHP?</a></li>
</ul>
<p>The post <a href="https://www.johnpatel.com/php-foreach-loop/">PHP Foreach Loop Implementation with Example</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">914</post-id>	</item>
	</channel>
</rss>
