Jump to content

Email form help


Lastbreath

Recommended Posts

Hi im new to webdesigning, so ive made this portfolio http://vasilstojanoski.atspace.eu, the issue is with the email form on the last tab, now if i make mail at the host cpanel i can send mails from the form, and if i dont make it doesnt send mails, also i get annoyed that whenever i test it with different mail, when i check the mail it always says its sended from the mail that i have on the host not the one that i type in the input. i found this 2 codes and little messed arround, they both work at localhost both work at the website only the first doesnt work if i use $mailheader = "From: $email \r\n";

<?php
	
	$to = 'vasilstojanoski24@gmail.com';
	$from = $_POST['name'];
	$email = $_POST['email'];
	$subject = $_POST['subject'];
	$message = $_POST['message'];
		
	// 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";
	
	$message = " $message \r \n ";
	$mailheader = "From: $email \r\n";
	

	if ($_POST['submit']) {
	    if (mail ($to, $subject, $message, $mailheader,$headers)) { 
	        echo '<p>Your message has been sent!</p>';
	    } else { 
	        echo '<p>Something went wrong, go back and try again!</p>'; 
	    }

	}
?>
<?php

// Used for later to determine result
$success = $error = false;

if (!empty($_POST)) {
	

	// Object syntax looks better and is easier to use than arrays to me
	$post = new stdClass;
	
	// Usually there would be much more validation and filtering, but this
	// will work for now.
	foreach ($_POST as $key => $val)
		$post->$key = trim(strip_tags($_POST[$key]));
		
	// Check for blank fields
	if (empty($post->name) OR empty($post->email) OR empty($post->subject) OR empty($post->message))
		$error = true;
		
	else {
		
		// Load the SwiftMailer files
		require_once'swift/swift_required.php';
		
		// Mail
		$transport = Swift_MailTransport::newInstance();
				
		// Create the Mailer using your created Transport
		$mailer = Swift_Mailer::newInstance($transport);

		$message = Swift_Message::newInstance()
				       ->setSubject($post->subject) // Message subject
					   ->setTo(array('vasil.stojanoski24@gmail.com' => 'Vasil Stojanoski Portfolio')) // Array of people to send to
					   ->setFrom(array($post->email => $post->name)) // From:
					   ->setBody($post->message, 'text/html');
					   
		
		 
         // Send the email, and show user message  
        $result = $mailer->send($message);
        header('Location: index.php');      
	}
}	

?>

so can u tell me wich one is better to use, the first wich is simple, or second that uses swiftmailer, and how to fix that instead of getting from: domain@mail to get the mail that is used in the input filed?

Link to comment
Share on other sites

 

Use swiftMailer.

 

This line of code is correct:

->setFrom(array($post->email => $post->name)) // From:

 

Tnx for the reply.

 

Yes m8 i also think the code is correct, but it doesnt work mean it doesnt put out test@yahoo.com and i dont know why, everytime i put different mail and open it in my gmail it says it comes from the mail that ive made on my host page test@atspace.com. ill try contact the host support coz i think something doesnt work properly from their side, coz a friend of mine uses simular swiftmailer code he is on another host, he didnt had to make mail on the host so the option to send mails to work.

Link to comment
Share on other sites

Try to run next code and tell me what you get:

<?php
$from = "From: jazz <jazzman@jazzman.com>";
$to = "you@yourdomain.com"; // your gmail account
$subject = "Hi! ";
$body = "TEST";

if(mail($to,$subject,$body,$from)) echo "MAIL - OK";
else echo "MAIL FAILED";
Edited by jazzman1
Link to comment
Share on other sites

 

Try to run next code and tell me what you get:

<?php
$from = "From: jazz <jazzman@jazzman.com>";
$to = "you@yourdomain.com"; // your gmail account
$subject = "Hi! ";
$body = "TEST";

if(mail($to,$subject,$body,$from)) echo "MAIL - OK";
else echo "MAIL FAILED";

 

Tryed still same From: mail@vasilstojanoskiatspace.eu not jazzman@jazzman.com, if i remove that mail at the host, message fails.

Link to comment
Share on other sites

Try with the code that I provided you above, then switch to swiftmaler, it should be OK.

 

Hmm ive tryed and still the same, then i checked faq it says :

Our servers require SMTP authentication, which in plain English means you will have to use any of your e-mail accounts, created within the E-mail Manager -> E-mail Accounts section from your control panel.

with other words, i need to use headers, or there is another way?

Link to comment
Share on other sites

Is there a way to control what ports are open or closed for your hosting plan? Port 25 is open, close it, you don't need to be open unless you have some application that is setup to send email notices from the hosting server.

 

trying to find , but as i see there isnt a way to get to port 25 smtp options.

Link to comment
Share on other sites

Sorry i dont understand , mail them?  i must have email on the host so the form is able to send mails. and the wrong in the headers is that From: its always the host mail account, not the one entered in the input, that now goes in the reply to: , its kinda stupid im searching a way that not to be shown and cant find.

 

this is the code atm, and setFrom is not fetching and sending what setReplyTo is.   im gonna try some other script instead of swiftmailer tommorrow, or maybe some other host ill see

$message = Swift_Message::newInstance()
  ->setSubject($post->subject) // Message subject
  ->setTo(array('vasil.stojanoski24@gmail.com' => 'Vasil Stojanoski Portfolio')) // Array of people to send to
  ->setFrom(array($post->email => $post->name)) // From:
  ->setReplyTo(array($post->email => $post->name))
  ->setBody($post->message, 'text/html');
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.