I upload the PHP script to two different domains, but the A domain/server is not working and the B domain/server is able to receive the email message. Someone says that it may be the server setting issue, and someone says that is the script issue. Can anyone help or must use the STMP format only able to work on a certain domain? How to use STMP as I still new in PHP.
<?php
if ($_GET) {
$Name = $_GET['Name'];
$Email = $_GET['Email'];
$Phone = $_GET['phonefull'] . $_GET['Phone'];
$Message = $_GET['Message'];
$Country = $_GET['country'];
$Departmnet = $_GET['Department'];
$PreferedDate = $_GET['PreferedDate'];
$DOB = $_GET['dob'];
$PreferedTime = $_GET['PreferedTime'];
$mine_email = "enquiry#ahppl.com.sg";
if ($_GET['Department'] == 'imaging') {
$to = "ljack4167#gmail.com";
} elseif ($_GET['Department'] == 'Wellness') {
$to = "ctjohn93#gmail.com";
} elseif ($_GET['Department'] == 'Aesthetics') {
$to = "aesthetics#ahppl.com";
}
$subject = "For Appoinment";
$message = '<html><body>';
$message .= "<table border='1px'>
<thead>
<th>Name</th>
<th>Phone</th>
<th>Country</th>
<th>DOB</th>
<th>Email</th>
<th>Department</th>
<th>Preferred Date</th>
<th>Preferred Time</th>
</thead>
<tbody>
<tr>
<td>" . $Name . " </td>
<td>" . $Phone . "</td>
<td>" . $Country . "</td>
<td>" . $DOB . "</td>
<td>" . $Email . "</td>
<td>" . $Departmnet . "</td>
<td>" . $PreferedDate . "</td>
<td>" . $PreferedTime . "</td>
</tr>
<tr>
<th colspan='8'> Message </th>
</tr>
<tr>
<td colspan='8'> " . $Message . "</td>
</tr>
</tbody>
</table>";
$message .= '</body></html>';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$retval = mail($to, $subject, $message, $headers);
if ($retval == true) {
?>
<script>
localStorage.setItem("mailsend", "true");
window.location = "../index.html";
</script>
<?php
} else {
echo "Message could not be sent...";
}
}
?>
A mail sending issue can be a server issue or php script issue as you said. But for sure you can debug them.
If you are new and want to send emails, then I would suggest using any Mail Libraries in PHP.
PHPMailer is one such library for sending emails and make them less painful. The link is given below.
PHPMailer
If you are using SMTP for sending emails then you should verify the ports (Eg: 25, 465 etc) are open depending upon the protocol you are using. And I would suggest always using some Fake SMTP Server for testing. Mailtrap can do that job for you.
Link to Mail Trap: MailTrap.
I hope these 2 should do the job for you.
Related
I want to send email with multiple rows from database in php but when I send email that time send multiple email with single row data but I want single email with multiple rows.
I don't know where I am wrong. Below is my running code in php and mysql.
$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");
for ($i = 0; $i < count($fm_id); $i++)
{
$update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
$res=mysql_query($update);
$update1=("UPDATE fm_status SET date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
$res1=mysql_query($update1);
$to ='abc#gmail.com'. ', ';
$to .='abc#abc.com';
$subject="Ticket Details from ";
$header="Solution ";
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: FM Engineer<solution#abc.com>' . "\r\n" ;
$message = '<html><body>';
$message .= '<head>';
$message .= '</head>';
$message .= " <align=center> <div id='apDiv2'>
<table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
<thead>
<tr>
<th><h3> Raised By </h3></th>
<th><h3> Issue </h3></th>
<th><h3> Resolution </h3></th>
<th><h3> Status </h3></th>
</tr> </thead>
<tbody>
<td> ".$issue[$i]."</td>
<td> ".$issue[$i]."</td>
<td> ".$resolution[$i]."</td>
<td> ".$issue[$i]."</td>
</tr><tbody></table>";
$message .= '<br>';
$message .= "</body></html>";
$sentmail = mail($to,$subject,$message,$header);
echo $sentmail;
}
I think this is more along the lines of what you are looking for (I am not going to reiterate the warnings regarding mysql_* functions). If you are trying to add rows to your table to send in one email, then just have the rows built by the for loop like so:
$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");
$to ='abc#gmail.com'. ', ';
$to .='abc#abc.com';
$subject="Ticket Details from ";
$header="Solution ";
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: FM Engineer<solution#abc.com>' . "\r\n" ;
$message = '<html>';
$message .= '<head>';
$message .= '</head><body>';
$message .= " <align=center> <div id='apDiv2'>
<table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
<thead>
<tr>
<th><h3> Raised By </h3></th>
<th><h3> Issue </h3></th>
<th><h3> Resolution </h3></th>
<th><h3> Status </h3></th>
</tr> </thead>
<tbody>";
for ($i = 0; $i < count($fm_id); $i++)
{
$update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
$res=mysql_query($update);
$update1=("UPDATE fm_status SET date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
$res1=mysql_query($update1);
$message .= "<tr>
<td> ".$issue[$i]."</td>
<td> ".$issue[$i]."</td>
<td> ".$resolution[$i]."</td>
<td> ".$issue[$i]."</td>
</tr>";
}
$message .= '<tbody></table><br>';
$message .= "</body></html>";
$sentmail = mail($to,$subject,$message,$header);
echo $sentmail;
I am confused by the use of single and double quotation marks, echo, and $message .=
I cannot figure out how to code a foreach loop inside my $message to output the cart items. The thead part works, but the tbody area is flawed. Any help is appreciated.
<?php
session_start();
// Initialize variables
$name = $telephone = $email = $jim_gmail = '';
// Post data from #quote-form.html.php
if( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'] ) ) {
// Sanitize and post data to variables
$company = sanitize( $_POST['company'] );
$name = sanitize( $_POST['name'] );
$telephone = sanitize( $_POST['telephone'] );
$email = sanitize( $_POST['email'] );
// Assign $name value to SESSION variable for use #thankyou.html.php
$_SESSION['name'] = $name;
// Initialize and declare variables for script validation
$errMsg = '';
$telephone_pattern = '/^((([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+)*$/';
$alpha_only_pattern = '/^[a-zA-Z]*$/';
$email_pattern = '/^([a-zA-Z0-9._%-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/';
$integers_pattern = '/^[0-9]*$/';
// Validate user data before submitting to server
if(empty($name) || empty($telephone) || empty($email))
{
$errMsg = "*Name, telephone and email address required.<br>";
include 'error.html.php';
}
elseif (preg_match($email_pattern,$email) === 0 )
{
$errMsg = "*Please enter a valid email address.<br>";
include 'error.html.php';
}
else
{
/* Prepare message for e-mail */
/* set e-mail recipient */
$jim_gmail = 'jim#gmail.com';
// Three required arguments ($to, $subject, $message)
$to = "$jim_gmail";
$subject = "Buyer for CraneHeli";
$from = "$email";
$message = // contents of report in $message
"
<html>
<head></head>
<body>
<h3>Parts Buyer</h3>
<p>Company: $company</p>
<p>Name: $name</p>
<p>Telephone: $telephone</p>
<p>Email: $email</p>
<h3>Please quote the following:</h3>
<table name='contact_seller' style='border-collapse:collapse';>
<thead>
<tr>
<th>ID</th>
<th>Part Number</th>
<th>Description</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php foreach($cart as $item): ?>
<tr>
<td>$item['id']</td>
<td>$item['part_number']</td>
<td>$item['description']</td>
<td>$item['quantity']</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p>End of buyer data report</p>
<hr />
</body>
</html>
"; //end of $message
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n"; // code to send HTML on UNIX
$headers .= 'Content-type:text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Bcc: ' . $jim_gmail . "\r\n"; // works
$headers .= 'Bcc: ' . $jim_gmail . "\r\n"; // works
// Send message using mail() function
mail($to, $subject, $message, $headers);
// Check to see if headers not sent. If true, redirect to thank_you.php page
if(!headers_sent()){
header('Location: thankyou.html.php');
exit();
}else{
echo "<span class='errMsg'>Message sent successfully!</span><br><br>" .
"Cannot redirect, please click this <a " .
"href=\".\">link</a> instead\n";
}
exit();
}
/******* Functions used *******/
function sanitize($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
You're nearly there:
$message = // contents of report in $message
"
<html>
<head></head>
<body>
<h3>Parts Buyer</h3>
<p>Company: $company</p>
<p>Name: $name</p>
<p>Telephone: $telephone</p>
<p>Email: $email</p>
<h3>Please quote the following:</h3>
<table name='contact_seller' style='border-collapse:collapse';>
<thead>
<tr>
<th>ID</th>
<th>Part Number</th>
<th>Description</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>";
foreach($cart as $item) {
$message .="<tr>
<td>" . $item['id'] ."</td>
<td>".$item['part_number']."</td>
<td>".$item['description']."</td>
<td>".$item['quantity']."</td>
</tr>";
}
$message .= "</tbody>
</table>
<p>End of buyer data report</p>
<hr />
</body>
</html>"; //end of $message
Take note specifically of:
<tbody>";
foreach($cart as $item) {
$message .="<tr>
<td>" . $item['id'] ."</td>
<td>".$item['part_number']."</td>
<td>".$item['description']."</td>
<td>".$item['quantity']."</td>
</tr>";
}
$message .= "</tbody>
</table>
I'm working in PHP and I have a simple shopping cart which adds items when you click the add button.
Everything is collected in a variable called $cartOutput
When I echo it, it gives me everything in the cart as expected. Same with var_dump . Everything is there
However, when I try to put it in an email and send it off. It cuts off the first item. Can anyone think of why this might be?
Nothing filters it before it is put into the email. It is simply what is in the variable
here is an example...
// e.g of the php variable being assembled for each item
$cartOutput .= "<tr>";
$cartOutput .= "<td>" . $product_name . "</td>";
$cartOutput .= "<td>$" . $price . "</td>";
// emailing the variables off here
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$commercialAdd = $_POST['commercial'];
$residentialAdd = $_POST['residential'];
$city = $_POST['city'];
$province = $_POST['province'];
$postal_code = $_POST['postal_code'];
$email = $_POST['email'];
$special_instructions = $_POST['special_instructions'];
$date = date("Y/m/d");
$time = date("h:i:sa");
$to = "xxx#gmail.com";
$header = "Cc:xxx#somedomain.com \r\n";
$subject = "Email Order - $company ($date - $time)";
$message = <<<EOD
<h1>Email Order - $date - $time </h1>
<h3><strong><u>Company:</u></strong> $company</h3>
<h3><strong><u>Name:</u></strong> $Name </h3>
<h3><strong><u>Address:</u></strong> $address<br>
$address2</h3>
<h3><strong><u>Residential:</u></strong> $commercialAdd </h3>
<h3><strong><u>Commercial:</u></strong> $residentialAdd </h3>
<h3><strong><u>City:</u></strong> $city</h3>
<h3><strong><u>Province:</u></strong> $province</h3>
<h3><strong><u>Postal Code:</u></strong> $postal_code</h3>
<h3><strong><u>Phone Number:</u></strong> $phone</h3>
<h3><strong><u>Email:</u></strong> $email</h3>
<h3><strong><u>Special Instructions:</u></strong> $special_instructions</h3>
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Weight (Kg)</th>
<th>Qty</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
<tbody>
$cartOutput
<tr>
<td class="totals"><strong>Total</strong></td>
<td class="totals"> </td>
<td class="totals">$weightTotal kg</td>
<td class="totals">$quantityTotal</td>
<td class="totals">$ $cartTotal</td>
<td class="totals"> </td>
<tr>
</tbody>
</table>
EOD;
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
header("location: complete.php");
exit();
}
else {
echo "Order could not be sent. Please try again or contact our office for assistance";
}
}
Probably you are running into an email format issue. mail() requires the body to end each line in \r\n AND be less than 70 characters each. You will need to encode you HTML or include it as an attachment. See this set of instructions for an example.
I am trying to echo a for loop inside a html mail message, the loop is
for($i=0; $i<$arrlength; $i++)
{
echo $mailroom[$i] ;
if ($i<($arrlength-1) )
{
echo " & ";
}
}
It is printing the results perfectly, but it not printing any result at the html message, the html message is
$headers = "From: ". "XXXX" . "<" . $frommail . ">\r\n";
$headers .= "Reply-To: " . $frommail . "\r\n";
$headers .= "Return-path: ". $frommail;
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$sendmessage = "
<html>
<head>
<title>XXXXXX DETAILS</title>
</head>
<body>
<p>DATA FOR XXXXXXXXXX</p>
<table border=1>
<tr>
<th>Booked on</th>
<th>Name</th>
<th>Bank</th>
<th>UIN</th>
<th>Phone</th>
<th>From</th>
<th>To</th>
<th>Room No.s</th>
<th>Tariff</th>
<th>Caution Money</th>
<th>Courier</th>
<th>Bank Charges</th>
<th>Total Received</th>
</tr>
<tr>
<td>$mailtoday</td>
<td>$name (ESP)</td>
<td> </td>
<td>$uin</td>
<td>$phone</td>
<td>$mailfrom</td>
<td>$mailto</td>
<td>
**for($i=0; $i<$arrlength; $i++)
{
echo $mailroom[$i] ;
if ($i<($arrlength-1) )
{
echo " & ";
}
}**
</td>
<td>$room_total</td>
<td>$c_money</td>
<td>$courier</td>
<td>$b_charges</td>
<td>$totalreceived</td>
</tr>
</table>
</body>
</html>
";
`
Can I put the for loop inside a variable so that I can use it withing the html message or otherwise later.
You have to close off your string before attempting to use a non-string value. In this case I'd do like this:
"<td>$name (ESP)</td>
<td> </td>
<td>$uin</td>
<td>$phone</td>
<td>$mailfrom</td>
<td>$mailto</td>
<td>" . implode(' & ', $mailroom) . "</td>
<td>$room_total</td>
<td>$c_money</td>"
You cannot use a for-loop (or any other statement for that matter) in a string.
Instead you need to concatenate your string inside the loop. For example:
$myString = "test ";
for($i = 0; $i < 3; $i++) {
$myString = $myString . "$i, ";
}
$myString = $myString . " end!";
echo $myString; // shows "test 1, 2, 3, end!"
(I created this small example, as you code snippet is quite long, but the same applies)
No,You can't do this. The double quotation marks is for variable replacement. Not for code running.
Try this
$headers = "From: ". "XXXX" . "<" . $frommail . ">\r\n";
$headers .= "Reply-To: " . $frommail . "\r\n";
$headers .= "Return-path: ". $frommail;
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$sendmessage = "
<html>
<head>
<title>XXXXXX DETAILS</title>
</head>
<body>
<p>DATA FOR XXXXXXXXXX</p>
<table border=1>
<tr>
<th>Booked on</th>
<th>Name</th>
<th>Bank</th>
<th>UIN</th>
<th>Phone</th>
<th>From</th>
<th>To</th>
<th>Room No.s</th>
<th>Tariff</th>
<th>Caution Money</th>
<th>Courier</th>
<th>Bank Charges</th>
<th>Total Received</th>
</tr>
<tr>
<td>$mailtoday</td>
<td>$name (ESP)</td>
<td> </td>
<td>$uin</td>
<td>$phone</td>
<td>$mailfrom</td>
<td>$mailto</td>
<td>";
for($i=0; $i<$arrlength; $i++)
{
$sendmessage.= $mailroom[$i] ;
if ($i<($arrlength-1) )
{
$sendmessage .= "& ";
}
}
$sendmessage.=" </td>
<td>$room_total</td>
<td>$c_money</td>
<td>$courier</td>
<td>$b_charges</td>
<td>$totalreceived</td>
</tr>
</table>
</body>
</html>";
use this code, you missed php opening <?php and closing ?> tags
$sendmessage .= ".........<td>";
for($i=0; $i<$arrlength; $i++)
{
$sendmessage .= $mailroom[$i] ;
if ($i<($arrlength-1) )
{
$sendmessage .= " & ";
}
}
$sendmessage .= "</td>.........";
Lately, I've made changes on my javascript code, just a simple contact form and also using colorbox plugin too. It's up and running for 5 days. For the first 2 days I received emails from the form after that I've made changes on the code that causes not to received the forms data from user. Since then, I didn't receive any emails. Is there a way to still retrieve and recover the data send from the form?
if (isset($_POST['register-form'])) {
$_POST = array_map('htmlentities', $_POST);
if ($_POST['type'] == '1') {
$status = "Professional";
}
if ($_POST['type'] == '2') {
$status = "Student";
}
/** Make the mail **/
$headers = "from: noreply#sample.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$subject = "Registration";
$mail = "<table border='0' width='100%' cellpadding='5' cellspacing='1'>
<tr>
<td witdth='15%'><strong>First Name</strong></td>
<td>{$_POST['first-name']}</td>
</tr>
<tr>
<td><strong>Last Name</strong></td>
<td>{$_POST['last-name']}</td>
</tr>
<tr>
<td><strong>Contact Number</strong></td>
<td>{$_POST['contact-number']}</td>
</tr>
<tr>
<td><strong>E-mail</strong></td>
<td>{$_POST['email']}</td>
</tr>
<tr>
<td><strong>Level</strong></td>
<td>{$status}</td>
</tr>
<tr>
<td><strong>Company/School</strong></td>
<td>{$_POST['company-name']}</td>
</tr>
</table>";
mail('sample91#gmail.com', $subject, $mail, $headers);
}