Jump to content

mail() problem


kney

Recommended Posts

I have this code in borrow.php

Whenever they click the button 'sendMail' an email is sent to that user who tries to borrow that specific book (the book details are left out cuz we don't need them here)

 

<?php
global $interface;
global $user;

if (isset($_POST['sendMail'])){
        $to = $partner->email;
$subject = "ILB Request";
if(!isset($user->id)){
	$lastname = $_POST['lastname'];
	$firstname = $_POST['firstname'];
	$email = $_POST['email'];
	$telephone = $_POST['telephone'];
	$fax = $_POST['fax'];
}else{
	$lastname = $user->lastname;
	$firstname = $user->firstname;
	$email = $user->email;
	$telephone = $user->telephone;
	$fax = $user->fax;
}
$message = "
<html>
<body>
<h2>Loaner Details</h2>
<table>
<tr>
<td>Name: </td>
<td>" . $lastname . "</td>
</tr>
<tr>
<td>First Name: </td>
<td>" . $firstname . "</td>
</tr>
<tr>
<td>Email: </td>
<td>" . $email . "</td>
</tr>
<tr>
<td>Telephone: </td>
<td>" . $telephone . "</td>
</tr>
<tr>
<td>Fax: </td>
<td>" . $fax . "</td>
</tr>
</table>
</body>
</html>
";

        // Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
    	if(!isset($user->id)){
	$headers .= 'From: <' . $_POST['email'] . '>' . "\r\n";
}else{
	$headers .= 'From: <' . $user->email . '>' . "\r\n";
}

if(!empty($email)){
	if(mail($to,$subject,$message,$headers)){
		$interface->assign('success', "Your IBL request has been sent succesfully!");
	}else{
		$interface->assign('success', "Your IBL request has failed!");
	}
}else{
	$interface->assign('success', "Email address has to be filled in!");
}
}

 

And then there is this code in Edit.php:

Whenever a person changes someone elses profile (like an admin), the person whos profile is being changed needs to be notified by email.

It's the same function as before though it gives this error:

"Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\vufind\web\services\MyResearch\Edit.php on line 182"

 

But the php.ini file hasn't been changed, and it doesn't give error the the previous code above (+ I receive the email)

So I add to the file below:

<?php
ini_set("SMTP","mySMTPserver.");
ini_set("smtp_port","25");
?>

 

and now i get this msg...

"Warning: mail(): SMTP server response: 503 5.5.2 Need Rcpt command."

 

<?php
global $interface;
global $user;

if (isset($_POST['submit'])) {
if(isset($_GET['userID'])){
$updateUser = new User();
if($user->id != $_GET['userID']){
        	$to = $updateUser->email;
	$subject = "Profile has been changed by " . $user->firstname . " " . $user->lastname;
	$message = "
	<html>
	<body>
	<h2>Notification</h2>
	<br /><br />
	Hi, <br /><br />
	This is an email notification you receive when your profile has been changed!
	</body>
	</html>";

        // Always set content-type when sending HTML email
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

	// More headers
	$headers .= 'From: admin@felnet.be' . "\r\n";

	echo $to . " " . $subject . " " . $message . " " . $headers;

        if(mail($to,$subject,$message,$headers)){
		$interface->assign('sent', "Success!");
	}else{
		$interface->assign('sent', "Fail!");
	}
}

Link to comment
Share on other sites

1st part.. from Borrow.php

 

<?php
if(!empty($email)){
if(mail($to,$subject,$message,$headers)){
	$interface->assign('success', "Your IBL request has been sent succesfully!");
}else{
	$interface->assign('success', "Your IBL request has failed!");
}
}else{
$interface->assign('success', "Email address has to be filled in!");
}
?>

 

2nd part... from Edit.php

 

<?php
if(mail($to,$subject,$message,$headers)){
$interface->assign('sent', "Success!");
}else{
$interface->assign('sent', "Fail!");
}
?>

 

Link to comment
Share on other sites

Run this code on a new page. ( $to = put u email address)

<?php
$to = "email address";   		
$from    = " <no-reply@sitename.info >";		
$headers = "MIME-Version: 1.0\r\n";		
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";		
$headers.= "From: $from\r\n";		
$mail_body = "Hello World";		
if (mail($to,"Mail", $mail_body,$headers))		
{	echo " Thankyou! - Your feedback has been sent! ";	}		
else		
{	echo " Thankyou! - We could not send email. Please try later! ";	}

Link to comment
Share on other sites

it gives this error

 

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\vufind\web\services\MyResearch\bibManageDocuments.php on line 24 

Thankyou! - We could not send email. Please try later! 

 

so i added this code , and now it works.. and on the Edit.php it doesn't work

 

<?php
ini_set("SMTP","smtp.vito.local");
ini_set("smtp_port","25");
?>

Link to comment
Share on other sites

The problem was in this part..

I created a new user but didn't specify which user to get the email address from.

It's fixed now!

 

Thanks for the help :)

 

<?php
$updateUser = new User();
// added this now
// -------------------
$updateUser->get('id', $_GET['userID']);
// -------------------
$to = $updateUser->email;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.