Going to form submission "success" page after form submission

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
indomtrading
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Oct 29, 2017 2:32 am

Sun Oct 29, 2017 2:50 am

r>Morning all<br/>
<br/>
I have the following code which allowed me to send a form to a specified email address, but want my website to go to an HTML page to confirm submission. However, it just goes black. Can anyone tell me what I'm missing here?<br/>

<CODE><s>

Code: Select all

</s><i>
</i><html>
	<body>
		<?php
			
			$require("file_directory")
			
			$goto_after_mail = "http://www.domain.com";
			$name = $_POST["firstName"];
			$surname = $_POST["surname"];
			$email=$_POST["yourEmail"];
			$message=$_POST["userMessage"];
		
			$from = new SendGrid\Email("Title","no_reply@domain.com");
			$subject = "You've got a new message";
			$to = new SendGrid\Email("Senders_Name","email_address");
			$headers = new SendGrid\Email($email);
			$content = new SendGrid\Content("text/html","
			<h1><b>Header Message Content</b></h1><br>
			Email: {$email}<br>
			Name: {$name}<br>
			Surname: {$surname}<br>
			$name wrote the following message<br><br>{$message}
			<br>
			<br>
			This email is unmonitored, therefore, please do not reply to this email. Instead, contact us on compliance@indomtrading.com
			<br><br>
			");
			$mail = new SendGrid\Mail($from, $sublect, $to, $headers, $content);
			$apiKey = ("API_key");
			$sg = new \SendGrid($apiKey);
			header("Location: ".$goto_after_mail);
		
			/*$response = $sg->client->mail()->send()->post($mail);
			$response="location."*/
		?>
	</body>
</html>
<e>
</e></CODE>

Many thanks</r>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 526
Joined: Mon Feb 22, 2016 5:52 pm

Sun Oct 29, 2017 4:07 am

Turn error reporting on, you have a couple of errors, but the big one is that you cannot send a header after you have output:

----------------------------------------------------------

This, apart from being incorrect html,:

Code: Select all

</s><i>
</i><html>
	<body>
Cannot go before:

Code: Select all

header("Location: ".$goto_after_mail);

indomtrading
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Oct 29, 2017 2:32 am

Sun Oct 29, 2017 4:50 am

hyper wrote:
Sun Oct 29, 2017 4:07 am
Turn error reporting on, you have a couple of errors, but the big one is that you cannot send a header after you have output:

----------------------------------------------------------

This, apart from being incorrect html,:

Code: Select all

</s><i>
</i><html>
	<body>
Cannot go before:

Code: Select all

header("Location: ".$goto_after_mail);
Awesome, how would I turn error reporting on?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 526
Joined: Mon Feb 22, 2016 5:52 pm

Sun Oct 29, 2017 5:57 am

Here's one way, but I suggest you do some research to find others.

There should also be a log file which you can view, again you will need to do some research as the location can vary depending on what system you are using.

I should have said "Turn error reporting to display errors". Make sure that you turn off display errors when putting your code on a live server.

indomtrading
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Oct 29, 2017 2:32 am

Wed Nov 01, 2017 12:49 am

Hello, I've created a function that saves an error loge file from my Dreamweaver, which has a server on XXAMP and using SendGrid for my mailing provider. I'm getting the following error.

Code: Select all

Started: 30/10/2017 08:55

handler_mail.php - Put operation successful
Mailing\sendgrid-php - error occurred - An error occurred - cannot put sendgrid-php.  Access is denied.  

File activity incomplete. 1 file(s) or folder(s) were not completed.
Files updated: 1
Files with errors: 1
Mailing\sendgrid-php

Finished: 30/10/2017 08:55
This is from my PHP code I'd developed, which was taken straight from the SendGrid API documentation;

Code: Select all

<?php


require('/.../sendgrid-php/sendgrid-php.php');

$name = $_POST["name"];
$surname = $_POST["surname"];
$email = $_POST["yourEmail"];
$message = $_POST["yourMessage"];

$from = new SendGrid\Email("Example User", "test@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Example User", "test@example.com");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$mail = new SendGrid\Mail($from, $subject, $to, $content);

$apiKey = getenv('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');

$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);

echo $response->statusCode();

print_r($response->headers());

echo $response->body();

?>


Thanks

Todd
Attachments
2017-10-28 (5).png
2017-10-28 (5).png (132.47 KiB) Viewed 99 times

Post Reply