- Code: Select all
<img src="http://cdn.onapp.com/images/logos/ipeer.png"><br>
<h2>Ipeer Mail Test script v1.0</h2>
Simple test to check server send ability.<br>
<br>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
To:<br>
<input name="to" type="text" value="" size ="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
$to=$_REQUEST['to'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail($to, $subject, $message, $from);
echo "Email sent!";
}
}
?>
To test SMTP/SMTPS authentication through PHP code:
Install required pear-mail modules:
pear install Mail-1.2.0
pear install Net_SMTP
- Code: Select all
<?php
require_once "Mail.php";
$from = "Name <From email address>"; //enter from email address
$to = "Name <To email address>"; //enter to email address
$subject = "Mail check through PHP script!";
$body = "Hello,\n\nMail check..!";
$host = "ssl://HOST_NAME"; //Enter SMTP hostname or IP, with SSL(SMTPS) or use 25/587
$port = "465"; //Change it accordingly as per above line
$username = "mailaddress"; //Auth email address
$password = "Password"; //Auth email pass
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent from $from to $to..! </p>"); }
?>
PHP Contact us form without Auth:
- Code: Select all
<img src="http://cdn.onapp.com/images/logos/ipeer.png"><br>
<h2>Ipeer Mail Test script v1.0</h2>
Simple test to check server send ability.<br>
<br>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
To:<br>
<input name="to" type="text" value="" size ="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
$to=$_REQUEST['to'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail($to, $subject, $message, $from);
echo "Email sent!";
}
}
?>
- Code: Select all
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("chandranjoy@gmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
How to connect to a database throgh PHP?
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
Enjoy

Simple PHP Mail Script - Without Authentication:
- Code: Select all
<?php
// The message
$message = "This is test mail from support team\r\nPlease ignore this\r\nDo not reply to this e-mail";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
echo mail('chandranjoy@gmail.com', 'From Support team - Please ignore this', $message);
?>
PHP Mail Script - With Authentication:
- Code: Select all
<?php
require_once "Mail.php";
$from = "Test <test@domain.com>";
$to = "Recepient <testingdot123@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "localhost";
$username = "test@domain.com";
$password = "test";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
PHP Mail Script Without Authentication:
- Code: Select all
<?php
$to = 'he@hisdomain.com';
$subject = 'this is the subject of the mail';
$message = 'this is the body of the mail';
$headers = 'From: me@mydomain.com' . "\r\n" .
'Reply-To: me@mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>